Skip to content

Commit

Permalink
Merge pull request #1403 from gnocchixyz/mergify/bp/stable/4.6/pr-1374
Browse files Browse the repository at this point in the history
Redis: Fix sentinel fallbacks with IPv6 address (backport #1374)
  • Loading branch information
tobias-urdin authored Aug 20, 2024
2 parents bc02daf + 7973a5e commit 0873cdf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gnocchi/common/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.

import re

from oslo_config import cfg
from urllib import parse

Expand Down Expand Up @@ -113,6 +115,18 @@
]


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')


def get_client(conf, scripts=None):
if redis is None:
raise RuntimeError("Redis Python module is unavailable")
Expand Down Expand Up @@ -152,7 +166,7 @@ def get_client(conf, scripts=None):
# sentinel arg.
if 'sentinel' in kwargs:
sentinel_hosts = [
tuple(fallback.split(':'))
_parse_sentinel(fallback)
for fallback in kwargs.get('sentinel_fallback', [])
]
sentinel_hosts.insert(0, (kwargs['host'], kwargs['port']))
Expand Down

0 comments on commit 0873cdf

Please sign in to comment.