diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index 9b2ef031..42422136 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -17,6 +17,7 @@ from distutils import version import functools import logging +import re import string import threading @@ -417,6 +418,18 @@ return 1 _dumps = staticmethod(utils.dumps) _loads = staticmethod(utils.loads) + @classmethod + def _parse_sentinel(cls, sentinel): + # IPv6 (eg. [::1]:6379 ) + match = re.search(r'\[(\S+)\]:(\d+)', sentinel) + if match: + return (match[1], int(match[2])) + # IPv4 or hostname (eg. 127.0.0.1:6379 or localhost:6379) + match = re.search(r'(\S+):(\d+)', sentinel) + if match: + return (match[1], int(match[2])) + raise ValueError('Malformed sentinel server format') + @classmethod def _make_client(cls, parsed_url, options, default_socket_timeout): kwargs = {} @@ -451,7 +464,7 @@ return 1 # sentinel arg. if 'sentinel' in kwargs: sentinel_hosts = [ - tuple(fallback.split(':')) + cls._parse_sentinel(fallback) for fallback in kwargs.get('sentinel_fallback', []) ] sentinel_hosts.insert(0, (kwargs['host'], kwargs['port']))