Skip to content

Commit

Permalink
Fix cluster_mode in returner/token module
Browse files Browse the repository at this point in the history
`StrictRedisCluster` was renamed to `RedisCluster` in v2 of `redis-py-cluster`,
which has only been accounted for in the cache module.

Note that `redis-py-cluster` has not been necessary since v4.1.0 of `redis-py`
and is archived, we should port this to use `redis-py` instead and drop the
second dependency altogether.

For reference: https://github.com/grokzen/redis-py-cluster
  • Loading branch information
hackruu authored Feb 14, 2025
1 parent 438839b commit dc50168
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/18.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed saltext-redis is not working correctly with clustered redis
5 changes: 3 additions & 2 deletions src/saltext/redis/returners/redis_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

try:
# pylint: disable=no-name-in-module
from rediscluster import StrictRedisCluster
from rediscluster import RedisCluster

# pylint: enable=no-name-in-module

Expand Down Expand Up @@ -189,9 +189,10 @@ def _get_serv(ret=None):
if REDIS_POOL:
return REDIS_POOL
elif _options.get("cluster_mode"):
REDIS_POOL = StrictRedisCluster(
REDIS_POOL = RedisCluster(
startup_nodes=_options.get("startup_nodes"),
skip_full_coverage_check=_options.get("skip_full_coverage_check"),
password=_options.get("password"),
decode_responses=True,
)
else:
Expand Down
6 changes: 2 additions & 4 deletions src/saltext/redis/tokens/rediscluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ def __virtual__():

def _redis_client(opts):
"""
Connect to the redis host and return a StrictRedisCluster client object.
Connect to the redis host and return a RedisCluster client object.
If connection fails then return None.
"""
redis_host = opts.get("eauth_redis_host", "localhost")
redis_port = opts.get("eauth_redis_port", 6379)
try:
return rediscluster.StrictRedisCluster(
host=redis_host, port=redis_port, decode_responses=True
)
return rediscluster.RedisCluster(host=redis_host, port=redis_port, decode_responses=True)
except rediscluster.exceptions.RedisClusterException as err:
log.warning("Failed to connect to redis at %s:%s - %s", redis_host, redis_port, err)
return None
Expand Down

0 comments on commit dc50168

Please sign in to comment.