# HG changeset patch # User Marcin Kuzminski # Date 2019-09-22 16:03:42 # Node ID 9979cb94da5cded43d139bee58b6adbbd9cb2db5 # Parent baf64debbd080e9e878bf1ee0bfba06d742ad0dc caches: added redis pool for redis cache backend diff --git a/vcsserver/lib/rc_cache/backends.py b/vcsserver/lib/rc_cache/backends.py --- a/vcsserver/lib/rc_cache/backends.py +++ b/vcsserver/lib/rc_cache/backends.py @@ -20,6 +20,8 @@ import errno import logging import msgpack +import redis + from dogpile.cache.api import CachedValue from dogpile.cache.backends import memory as memory_backend from dogpile.cache.backends import file as file_backend @@ -124,6 +126,9 @@ class FileNamespaceBackend(PickleSeriali arguments['lock_factory'] = CustomLockFactory super(FileNamespaceBackend, self).__init__(arguments) + def __repr__(self): + return '{} `{}`'.format(self.__class__, self.filename) + def list_keys(self, prefix=''): prefix = '{}:{}'.format(self.key_prefix, prefix) @@ -167,6 +172,23 @@ class FileNamespaceBackend(PickleSeriali class BaseRedisBackend(redis_backend.RedisBackend): + + def _create_client(self): + args = {} + + if self.url is not None: + args.update(url=self.url) + + else: + args.update( + host=self.host, password=self.password, + port=self.port, db=self.db + ) + + connection_pool = redis.ConnectionPool(**args) + + return redis.StrictRedis(connection_pool=connection_pool) + def list_keys(self, prefix=''): prefix = '{}:{}*'.format(self.key_prefix, prefix) return self.client.keys(prefix)