Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis: Fix sentinel fallbacks with IPv6 address (backport #1374) #1403

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading