當前位置: 首頁>>代碼示例>>Python>>正文


Python StrictRedis.from_url方法代碼示例

本文整理匯總了Python中redis.StrictRedis.from_url方法的典型用法代碼示例。如果您正苦於以下問題:Python StrictRedis.from_url方法的具體用法?Python StrictRedis.from_url怎麽用?Python StrictRedis.from_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.StrictRedis的用法示例。


在下文中一共展示了StrictRedis.from_url方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def __init__(self, *args, **kwargs):
        app = kwargs['app']
        self.key = app.conf.get("CELERY_REDIS_SCHEDULER_KEY",
                                "celery:beat:order_tasks")
        self.schedule_url = app.conf.get("CELERY_REDIS_SCHEDULER_URL",
                                         "redis://localhost:6379")
        # using sentinels
        # supports 'sentinel://:pass@host:port/db
        if self.schedule_url.startswith('sentinel://'):
            self.broker_transport_options = app.conf.get("CELERY_BROKER_TRANSPORT_OPTIONS", {"master_name": "mymaster"})
            self.rdb = self.sentinel_connect(self.broker_transport_options['master_name'])
        else:
            self.rdb = StrictRedis.from_url(self.schedule_url)
        Scheduler.__init__(self, *args, **kwargs)
        app.add_task = partial(self.add, self)

        self.multi_node = app.conf.get("CELERY_REDIS_MULTI_NODE_MODE", False)
        # how long we should hold on to the redis lock in seconds
        if self.multi_node:
            self.lock_ttl = current_app.conf.get("CELERY_REDIS_SCHEDULER_LOCK_TTL", 30)
            self._lock_acquired = False
            self._lock = self.rdb.lock('celery:beat:task_lock', timeout=self.lock_ttl)
            self._lock_acquired = self._lock.acquire(blocking=False) 
開發者ID:liuliqiang,項目名稱:redisbeat,代碼行數:25,代碼來源:scheduler.py

示例2: test_end_to_end

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def test_end_to_end(redis_db):
    config = {
        REDIS_URIS_KEY: {
            'server': redis_db
        }
    }

    container = ServiceContainer(ExampleService, config)
    container.start()

    # write through the service
    with entrypoint_hook(container, "write") as write:
        write("foobar")

    # verify changes written to redis
    client = StrictRedis.from_url(redis_db, decode_responses=True)
    assert client.get(TEST_KEY) == "foobar"

    # read through the service
    with entrypoint_hook(container, "read") as read:
        assert read() == "foobar" 
開發者ID:etataurov,項目名稱:nameko-redis,代碼行數:23,代碼來源:test_nameko_redis.py

示例3: test_options

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def test_options(self, strict_redis_cls):
        client = Redis(
            'redis-uri',
            decode_responses=False,
            retry_on_timeout=True,
            socket_timeout=2,
            encoding='utf-8'
        )
        client.redis_uri = 'redis-uri'

        client.start()

        expected_options = {
            'decode_responses': False,
            'retry_on_timeout': True,
            'socket_timeout': 2,
            'encoding': 'utf-8',
        }

        assert [
            call('redis-uri', **expected_options)
        ] == strict_redis_cls.from_url.call_args_list 
開發者ID:etataurov,項目名稱:nameko-redis,代碼行數:24,代碼來源:test_nameko_redis.py

示例4: redis

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def redis(self):
        """
        Lazy-loaded redis connection
        """
        from redis import StrictRedis
        import redis.exceptions

        try:
            url = os.environ.get('REDIS_CONNECTION_URL',
                                 'redis://localhost:6379/0')
            conn = StrictRedis.from_url(url)
            conn.ping()
        except redis.exceptions.ConnectionError:
            logging.fatal("Redis server is not running")
            raise
        return conn 
開發者ID:GrafeasGroup,項目名稱:tor,代碼行數:18,代碼來源:config.py

示例5: main

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def main():
    r = StrictRedis.from_url(os.environ['REDIS_BASE_URL'], decode_responses=True)

    all_users = r.smembers('s:users')

    for username in all_users:
        lower_username = username.lower()

        if r.hexists(UserManager.LC_USERNAMES_KEY, lower_username):
            print('case dupe, no case lookup for: ' + username)
            value = '-'
        else:
            value = username if lower_username != username else ''

        r.hset(UserManager.LC_USERNAMES_KEY, lower_username, value)
        print('case map: {0} -> {1}'.format(username, value)) 
開發者ID:Rhizome-Conifer,項目名稱:conifer,代碼行數:18,代碼來源:migrate4.1.4.py

示例6: __init__

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def __init__(self, connection_str, db=0, project=None,
                 service=None, host=None, conf=cfg.CONF, **kwargs):
        """Redis driver for OSProfiler."""

        super(Redis, self).__init__(connection_str, project=project,
                                    service=service, host=host,
                                    conf=conf, **kwargs)
        try:
            from redis import StrictRedis
        except ImportError:
            raise exc.CommandError(
                "To use OSProfiler with Redis driver, "
                "please install `redis` library. "
                "To install with pip:\n `pip install redis`.")

        # only connection over network is supported with schema
        # redis://[:password]@host[:port][/db]
        self.db = StrictRedis.from_url(self.connection_str)
        self.namespace_opt = "osprofiler_opt:"
        self.namespace = "osprofiler:"  # legacy
        self.namespace_error = "osprofiler_error:" 
開發者ID:openstack,項目名稱:osprofiler,代碼行數:23,代碼來源:redis_driver.py

示例7: init_redis

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def init_redis(config):
    """ Init redis from config, with fallback to localhost
    """
    try:
        rc = StrictRedis.from_url(config['redis_url'])
        rc.ping()
    except:
        rc = StrictRedis.from_url('redis://localhost/')
        rc.ping()

    return rc 
開發者ID:ikreymer,項目名稱:browsertrix,代碼行數:13,代碼來源:worker.py

示例8: __init__

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def __init__(self, url):
        self.redis = StrictRedis.from_url(
            url, decode_responses=True, charset='utf-8'
        ) 
開發者ID:PacktPublishing,項目名稱:Python-Programming-Blueprints,代碼行數:6,代碼來源:messages.py

示例9: init_app

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def init_app(self, app, db, sentry):
        self.config = {
            "queues": app.config["QUEUES"],
            "routes": app.config["QUEUE_ROUTES"],
            "default_queue": app.config["QUEUE_DEFAULT"],
            "schedule": app.config["QUEUE_SCHEDULE"],
        }
        self.app = app
        self.db = db
        self.sentry = sentry

        self.connection = StrictRedis.from_url(
            app.config["REDIS_URL"], db=app.config["REDIS_DB"]
        ) 
開發者ID:getsentry,項目名稱:freight,代碼行數:16,代碼來源:queue.py

示例10: container_config

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def container_config(request, rabbit_config):
    """Redis and Rabbit configurations yielding

    Redis teardown is done here, Rabbit teardown is managed in `rabbit_config`.
    """
    config = rabbit_config
    config['REDIS_URI'] = request.config.getoption('REDIS_URI')
    yield config

    # use redis-py API directly to flush the db after each test
    # more elegant to use nameko API to access storage dep? how?
    def redis_teardown():
        client = StrictRedis.from_url(config['REDIS_URI'])
        client.flushdb()
    request.addfinalizer(redis_teardown) 
開發者ID:etalab,項目名稱:croquemort,代碼行數:17,代碼來源:conftest.py

示例11: __init__

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def __init__(self, store):
        self.rdb = StrictRedis.from_url(store)
        self.lock = None 
開發者ID:mixkorshun,項目名稱:celery-beatx,代碼行數:5,代碼來源:redis.py

示例12: redis_db

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def redis_db(request):
    url = 'redis://localhost/0'

    def redis_teardown():
        client = StrictRedis.from_url(url)
        client.delete(TEST_KEY)
    request.addfinalizer(redis_teardown)
    return url 
開發者ID:etataurov,項目名稱:nameko-redis,代碼行數:10,代碼來源:test_nameko_redis.py

示例13: test_default_options

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def test_default_options(self, strict_redis_cls):
        client = Redis('redis-uri')
        client.redis_uri = 'redis-uri'

        client.start()

        assert [
            call('redis-uri', decode_responses=True)
        ] == strict_redis_cls.from_url.call_args_list 
開發者ID:etataurov,項目名稱:nameko-redis,代碼行數:11,代碼來源:test_nameko_redis.py

示例14: start

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def start(self):
        self.client = _StrictRedis.from_url(self.redis_uri, **self.options) 
開發者ID:etataurov,項目名稱:nameko-redis,代碼行數:4,代碼來源:nameko_redis.py

示例15: __init__

# 需要導入模塊: from redis import StrictRedis [as 別名]
# 或者: from redis.StrictRedis import from_url [as 別名]
def __init__(self, old_redis_url, new_redis_url, dry_run=True,
                 per_recording_list=False, s3_import=False, s3_root=None):
        self.old_redis = StrictRedis.from_url(old_redis_url, decode_responses=True)
        self.dry_run = dry_run
        self.per_recording_list = per_recording_list
        self.s3_import = s3_import

        if s3_import:
            assert(s3_root)
            import boto3
            self.s3_root = s3_root
            self.s3 = boto3.client('s3')
        else:
            self.s3_root = None
            self.s3 = None

        if self.dry_run:
            import redis
            redis.StrictRedis = fakeredis.FakeStrictRedis
            self.redis = FakeStrictRedis.from_url(new_redis_url, decode_responses=True)
        else:
            self.redis = StrictRedis.from_url(new_redis_url, decode_responses=True)

        print('Redis Inited')

        self.cli = CLIUserManager(new_redis_url) 
開發者ID:Rhizome-Conifer,項目名稱:conifer,代碼行數:28,代碼來源:migrate4.0.py


注:本文中的redis.StrictRedis.from_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。