1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cache/redis: make keyset keyname configurable (#1036)

* FEATURE: make ansible_cache_keys name configurable

* REFACTOR: rename cache_keys to keyset

* FEATURE: add changelog fragment

* Update changelogs/fragments/1036-redis-cache-keyset-name.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Set version_added in plugins/cache/redis.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Benjamin Pereto <benjamin@sandchaschte.ch>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Benjamin Pereto 2020-10-11 13:16:59 +00:00 committed by GitHub
parent 434b83170a
commit 873f1fb7fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- redis cache plugin - make the redis cache keyset name configurable
(https://github.com/ansible-collections/community.general/pull/1036).

View file

@ -32,6 +32,15 @@ DOCUMENTATION = '''
ini:
- key: fact_caching_prefix
section: defaults
_keyset_name:
description: User defined name for cache keyset name.
default: ansible_cache_keys
env:
- name: ANSIBLE_CACHE_REDIS_KEYSET_NAME
ini:
- key: fact_caching_redis_keyset_name
section: defaults
version_added: 1.3.0
_timeout:
default: 86400
description: Expiration timeout in seconds for the cache plugin data. Set to 0 to never expire
@ -78,6 +87,7 @@ class CacheModule(BaseCacheModule):
uri = self.get_option('_uri')
self._timeout = float(self.get_option('_timeout'))
self._prefix = self.get_option('_prefix')
self._keys_set = self.get_option('_keyset_name')
except KeyError:
display.deprecated('Rather than importing CacheModules directly, '
'use ansible.plugins.loader.cache_loader',
@ -86,6 +96,7 @@ class CacheModule(BaseCacheModule):
uri = C.CACHE_PLUGIN_CONNECTION
self._timeout = float(C.CACHE_PLUGIN_TIMEOUT)
self._prefix = C.CACHE_PLUGIN_PREFIX
self._keys_set = 'ansible_cache_keys'
self._cache = {}
kw = {}
@ -96,7 +107,6 @@ class CacheModule(BaseCacheModule):
connection = uri.split(':')
self._db = StrictRedis(*connection, **kw)
self._keys_set = 'ansible_cache_keys'
def _make_key(self, key):
return self._prefix + key