def __init__(self, config):
BaseCache.__init__(self, config)
self.key_prefix = config.get('key_prefix', '')
try:
import redis
except ImportError:
raise RuntimeError('no redis module found')
kwargs = dict((k, v) for k, v in config.items() if k not in _redis_kwargs_exclusions)
if 'socket_timeout' not in kwargs:
kwargs['socket_timeout'] = _DEFAULT_SOCKET_TIMEOUT
if 'socket_connect_timeout' not in kwargs:
kwargs['socket_connect_timeout'] = _DEFAULT_SOCKET_TIMEOUT
if 'socket_keepalive' not in kwargs:
kwargs['socket_keepalive'] = 1
if 'socket_keepalive_options' not in kwargs:
kwargs['socket_keepalive_options'] = _TCP_KEEP_ALIVE_OPTIONS
if kwargs.pop('blocking_pool', False):
if 'blocking_pool_timeout' in kwargs:
kwargs['timeout'] = kwargs.pop('blocking_pool_timeout')
else:
kwargs['timeout'] = _DEFAULT_REDIS_BLOCKING_POOL_TIMEOUT
connection_pool = redis.BlockingConnectionPool(**kwargs)
else:
connection_pool = redis.ConnectionPool(**kwargs)
self._client = redis.Redis(connection_pool=connection_pool)
评论列表
文章目录