##// END OF EJS Templates
feat(redis): added redis prefix support for cache backend
super-admin -
r1313:cbb3f19b default
parent child Browse files
Show More
@@ -121,6 +121,10 b' vcs.svn.redis_conn = redis://redis:6379/'
121 ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
121 ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
122 #rc_cache.repo_object.arguments.lock_auto_renewal = true
122 #rc_cache.repo_object.arguments.lock_auto_renewal = true
123
123
124 ; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
125 #rc_cache.repo_object.arguments.key_prefix = custom-prefix-
126
127
124 ; Statsd client config, this is used to send metrics to statsd
128 ; Statsd client config, this is used to send metrics to statsd
125 ; We recommend setting statsd_exported and scrape them using Promethues
129 ; We recommend setting statsd_exported and scrape them using Promethues
126 #statsd.enabled = false
130 #statsd.enabled = false
@@ -101,6 +101,10 b' vcs.svn.redis_conn = redis://redis:6379/'
101 ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
101 ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
102 #rc_cache.repo_object.arguments.lock_auto_renewal = true
102 #rc_cache.repo_object.arguments.lock_auto_renewal = true
103
103
104 ; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
105 #rc_cache.repo_object.arguments.key_prefix = custom-prefix-
106
107
104 ; Statsd client config, this is used to send metrics to statsd
108 ; Statsd client config, this is used to send metrics to statsd
105 ; We recommend setting statsd_exported and scrape them using Promethues
109 ; We recommend setting statsd_exported and scrape them using Promethues
106 #statsd.enabled = false
110 #statsd.enabled = false
@@ -184,6 +184,9 b' class BaseRedisBackend(redis_backend.Red'
184 self._lock_timeout = self.lock_timeout
184 self._lock_timeout = self.lock_timeout
185 self._lock_auto_renewal = str2bool(arguments.pop("lock_auto_renewal", True))
185 self._lock_auto_renewal = str2bool(arguments.pop("lock_auto_renewal", True))
186
186
187 self._store_key_prefix = arguments.pop('key_prefix', '')
188 self.key_prefix = f'{self._store_key_prefix}{self.key_prefix}'
189
187 if self._lock_auto_renewal and not self._lock_timeout:
190 if self._lock_auto_renewal and not self._lock_timeout:
188 # set default timeout for auto_renewal
191 # set default timeout for auto_renewal
189 self._lock_timeout = 30
192 self._lock_timeout = 30
@@ -243,7 +246,7 b' class BaseRedisBackend(redis_backend.Red'
243
246
244 def get_mutex(self, key):
247 def get_mutex(self, key):
245 if self.distributed_lock:
248 if self.distributed_lock:
246 lock_key = f'_lock_{safe_str(key)}'
249 lock_key = f'{self._store_key_prefix}_lock_{safe_str(key)}'
247 return get_mutex_lock(
250 return get_mutex_lock(
248 self.writer_client, lock_key,
251 self.writer_client, lock_key,
249 self._lock_timeout,
252 self._lock_timeout,
@@ -69,11 +69,9 b' class RhodeCodeCacheRegion(CacheRegion):'
69 return result
69 return result
70
70
71 key = func_key_generator(*arg, **kw)
71 key = func_key_generator(*arg, **kw)
72 timeout = expiration_time() if expiration_time_is_callable else expiration_time
73 log.debug('Calling cached (timeout=%s) method:`%s`', timeout, user_func.__name__)
72
74
73 timeout = expiration_time() if expiration_time_is_callable \
74 else expiration_time
75
76 log.debug('Calling cached method:`%s`', user_func.__name__)
77 return self.get_or_create(key, user_func, timeout, should_cache_fn, (arg, kw))
75 return self.get_or_create(key, user_func, timeout, should_cache_fn, (arg, kw))
78
76
79 def cache_decorator(user_func):
77 def cache_decorator(user_func):
General Comments 0
You need to be logged in to leave comments. Login now