本文整理汇总了Python中pyramid.registry.Registry.redis方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.redis方法的具体用法?Python Registry.redis怎么用?Python Registry.redis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.registry.Registry
的用法示例。
在下文中一共展示了Registry.redis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_redis
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import redis [as 别名]
def init_redis(registry: Registry, connection_url=None, redis_client=StrictRedis, **redis_options):
"""Sets up Redis connection pool once at the start of a process.
Connection pool life cycle is the same as Pyramid registry which is the life cycle of a process (all threads).
"""
# if no url passed, try to get it from pyramid settings
url = registry.settings.get('redis.sessions.url') if connection_url is None else connection_url
# otherwise create a new connection
if url is not None:
# remove defaults to avoid duplicating settings in the `url`
redis_options.pop('password', None)
redis_options.pop('host', None)
redis_options.pop('port', None)
redis_options.pop('db', None)
# the StrictRedis.from_url option no longer takes a socket
# argument. instead, sockets should be encoded in the URL if
# used. example:
# unix://[:password]@/path/to/socket.sock?db=0
redis_options.pop('unix_socket_path', None)
# connection pools are also no longer a valid option for
# loading via URL
redis_options.pop('connection_pool', None)
redis = redis_client.from_url(url, **redis_options)
else:
raise RuntimeError("Redis connection options missing. Please configure redis.sessions.url")
registry.redis = redis