From cf6d4ecac1c6d2050260e5181354b4a602f9924e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 1 Oct 2024 16:58:47 +0900 Subject: [PATCH] Use oslo.utils implementation to parse sentinel address ... instead of maintaining own logic. Change-Id: I90d65f3e5b1be6b32e8c44a018c85c01ca47d3b2 --- tooz/drivers/redis.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tooz/drivers/redis.py b/tooz/drivers/redis.py index c891ac77..07711f61 100644 --- a/tooz/drivers/redis.py +++ b/tooz/drivers/redis.py @@ -16,11 +16,11 @@ import functools import logging -import re import string import threading from oslo_utils import encodeutils +from oslo_utils import netutils from oslo_utils import strutils from packaging import version import redis @@ -426,15 +426,10 @@ return 1 @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') + host, port = netutils.parse_host_port(sentinel) + if host is None or port is None: + raise ValueError('Malformed sentinel server format') + return (host, port) @classmethod def _make_client(cls, parsed_url, options, default_socket_timeout):