mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-14 04:09:11 -07:00
* better parsing of connection uri
* added changelog fragment
* fixed tests for ansible 2.9
* Update tests/unit/plugins/cache/test_redis.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update tests/unit/plugins/cache/test_redis.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Adjustments from PR
* Update test_redis.py
* Update test_redis.py
* Update plugins/cache/redis.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/cache/redis.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update tests/unit/plugins/cache/test_redis.py
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 4764a5deba
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
4d6735bebf
commit
7426c3839e
3 changed files with 28 additions and 3 deletions
14
plugins/cache/redis.py
vendored
14
plugins/cache/redis.py
vendored
|
@ -61,6 +61,7 @@ DOCUMENTATION = '''
|
|||
type: integer
|
||||
'''
|
||||
|
||||
import re
|
||||
import time
|
||||
import json
|
||||
|
||||
|
@ -91,6 +92,8 @@ class CacheModule(BaseCacheModule):
|
|||
performance.
|
||||
"""
|
||||
_sentinel_service_name = None
|
||||
re_url_conn = re.compile(r'^([^:]+|\[[^]]+\]):(\d+):(\d+)(?::(.*))?$')
|
||||
re_sent_conn = re.compile(r'^(.*):(\d+)$')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
uri = ''
|
||||
|
@ -130,11 +133,18 @@ class CacheModule(BaseCacheModule):
|
|||
self._db = self._get_sentinel_connection(uri, kw)
|
||||
# normal connection
|
||||
else:
|
||||
connection = uri.split(':')
|
||||
connection = self._parse_connection(self.re_url_conn, uri)
|
||||
self._db = StrictRedis(*connection, **kw)
|
||||
|
||||
display.vv('Redis connection: %s' % self._db)
|
||||
|
||||
@staticmethod
|
||||
def _parse_connection(re_patt, uri):
|
||||
match = re_patt.match(uri)
|
||||
if not match:
|
||||
raise AnsibleError("Unable to parse connection string")
|
||||
return match.groups()
|
||||
|
||||
def _get_sentinel_connection(self, uri, kw):
|
||||
"""
|
||||
get sentinel connection details from _uri
|
||||
|
@ -158,7 +168,7 @@ class CacheModule(BaseCacheModule):
|
|||
except IndexError:
|
||||
pass # password is optional
|
||||
|
||||
sentinels = [tuple(shost.split(':')) for shost in connections]
|
||||
sentinels = [self._parse_connection(self.re_sent_conn, shost) for shost in connections]
|
||||
display.vv('\nUsing redis sentinels: %s' % sentinels)
|
||||
scon = Sentinel(sentinels, **kw)
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue