本文整理匯總了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)
示例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"
示例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
示例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
示例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))
示例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:"
示例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
示例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'
)
示例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"]
)
示例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)
示例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
示例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
示例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
示例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)
示例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)