feat(redis): added ability to specify a redis key prefix for all cache regions of dogpile that use redis backend

This commit is contained in:
RhodeCode Admin 2024-10-23 22:11:27 +02:00
parent 465e9ede18
commit 7d196811c4
3 changed files with 28 additions and 1 deletions

View file

@ -485,6 +485,10 @@ rc_cache.cache_general.expiration_time = 43200
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_general.arguments.lock_auto_renewal = true #rc_cache.cache_general.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_general.arguments.key_prefix = custom-prefix-
; ************************************************* ; *************************************************
; `cache_perms` cache for permission tree, auth TTL ; `cache_perms` cache for permission tree, auth TTL
; for simplicity use rc.file_namespace backend, ; for simplicity use rc.file_namespace backend,
@ -512,6 +516,10 @@ rc_cache.cache_perms.expiration_time = 3600
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_perms.arguments.lock_auto_renewal = true #rc_cache.cache_perms.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_perms.arguments.key_prefix = custom-prefix-
; *************************************************** ; ***************************************************
; `cache_repo` cache for file tree, Readme, RSS FEEDS ; `cache_repo` cache for file tree, Readme, RSS FEEDS
; for simplicity use rc.file_namespace backend, ; for simplicity use rc.file_namespace backend,
@ -539,6 +547,10 @@ rc_cache.cache_repo.expiration_time = 2592000
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_repo.arguments.lock_auto_renewal = true #rc_cache.cache_repo.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_repo.arguments.key_prefix = custom-prefix-
; ############## ; ##############
; BEAKER SESSION ; BEAKER SESSION
; ############## ; ##############

View file

@ -453,6 +453,10 @@ rc_cache.cache_general.expiration_time = 43200
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_general.arguments.lock_auto_renewal = true #rc_cache.cache_general.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_general.arguments.key_prefix = custom-prefix-
; ************************************************* ; *************************************************
; `cache_perms` cache for permission tree, auth TTL ; `cache_perms` cache for permission tree, auth TTL
; for simplicity use rc.file_namespace backend, ; for simplicity use rc.file_namespace backend,
@ -480,6 +484,10 @@ rc_cache.cache_perms.expiration_time = 3600
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_perms.arguments.lock_auto_renewal = true #rc_cache.cache_perms.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_perms.arguments.key_prefix = custom-prefix-
; *************************************************** ; ***************************************************
; `cache_repo` cache for file tree, Readme, RSS FEEDS ; `cache_repo` cache for file tree, Readme, RSS FEEDS
; for simplicity use rc.file_namespace backend, ; for simplicity use rc.file_namespace backend,
@ -507,6 +515,10 @@ rc_cache.cache_repo.expiration_time = 2592000
; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen ; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen
#rc_cache.cache_repo.arguments.lock_auto_renewal = true #rc_cache.cache_repo.arguments.lock_auto_renewal = true
; prefix for redis keys used for this cache backend, the final key is constructed using {custom-prefix}{key}
#rc_cache.cache_repo.arguments.key_prefix = custom-prefix-
; ############## ; ##############
; BEAKER SESSION ; BEAKER SESSION
; ############## ; ##############

View file

@ -216,6 +216,9 @@ class BaseRedisBackend(redis_backend.RedisBackend):
self._lock_timeout = self.lock_timeout self._lock_timeout = self.lock_timeout
self._lock_auto_renewal = str2bool(arguments.pop("lock_auto_renewal", True)) self._lock_auto_renewal = str2bool(arguments.pop("lock_auto_renewal", True))
self._store_key_prefix = arguments.pop('key_prefix', '')
self.key_prefix = f'{self._store_key_prefix}{self.key_prefix}'
if self._lock_auto_renewal and not self._lock_timeout: if self._lock_auto_renewal and not self._lock_timeout:
# set default timeout for auto_renewal # set default timeout for auto_renewal
self._lock_timeout = 30 self._lock_timeout = 30
@ -275,7 +278,7 @@ class BaseRedisBackend(redis_backend.RedisBackend):
def get_mutex(self, key): def get_mutex(self, key):
if self.distributed_lock: if self.distributed_lock:
lock_key = f'_lock_{safe_str(key)}' lock_key = f'{self._store_key_prefix}_lock_{safe_str(key)}'
return get_mutex_lock( return get_mutex_lock(
self.writer_client, lock_key, self.writer_client, lock_key,
self._lock_timeout, self._lock_timeout,