Skip to content

Commit d425227

Browse files
authored
Migrated targeted nodes to kwargs in Cluster Mode (#1762)
1 parent e16e26e commit d425227

File tree

8 files changed

+342
-747
lines changed

8 files changed

+342
-747
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ and attempt to retry executing the command.
10461046
>>> rc.cluster_meet('127.0.0.1', 6379, target_nodes=Redis.ALL_NODES)
10471047
>>> # ping all replicas
10481048
>>> rc.ping(target_nodes=Redis.REPLICAS)
1049-
>>> # ping a specific node
1049+
>>> # ping a random node
10501050
>>> rc.ping(target_nodes=Redis.RANDOM)
10511051
>>> # get the keys from all cluster nodes
10521052
>>> rc.keys(target_nodes=Redis.ALL_NODES)
@@ -1158,7 +1158,7 @@ readwrite() method.
11581158
>>> from cluster import RedisCluster as Redis
11591159
# Use 'debug' log level to print the node that the command is executed on
11601160
>>> rc_readonly = Redis(startup_nodes=startup_nodes,
1161-
read_from_replicas=True, debug=True)
1161+
read_from_replicas=True)
11621162
>>> rc_readonly.set('{foo}1', 'bar1')
11631163
>>> for i in range(0, 4):
11641164
# Assigns read command to the slot's hosts in a Round-Robin manner

redis/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,18 @@ def __init__(
960960
def __repr__(self):
961961
return f"{type(self).__name__}<{repr(self.connection_pool)}>"
962962

963+
def get_encoder(self):
964+
"""
965+
Get the connection pool's encoder
966+
"""
967+
return self.connection_pool.get_encoder()
968+
969+
def get_connection_kwargs(self):
970+
"""
971+
Get the connection's key-word arguments
972+
"""
973+
return self.connection_pool.connection_kwargs
974+
963975
def set_response_callback(self, command, callback):
964976
"Set a custom Response Callback"
965977
self.response_callbacks[command] = callback

redis/cluster.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections import OrderedDict
99

1010
from redis.client import CaseInsensitiveDict, PubSub, Redis
11-
from redis.commands import ClusterCommands, CommandsParser
11+
from redis.commands import CommandsParser, RedisClusterCommands
1212
from redis.connection import ConnectionPool, DefaultParser, Encoder, parse_url
1313
from redis.crc import REDIS_CLUSTER_HASH_SLOTS, key_slot
1414
from redis.exceptions import (
@@ -94,6 +94,7 @@ def fix_server(*args):
9494
"charset",
9595
"connection_class",
9696
"connection_pool",
97+
"client_name",
9798
"db",
9899
"decode_responses",
99100
"encoding",
@@ -198,7 +199,7 @@ class ClusterParser(DefaultParser):
198199
)
199200

200201

201-
class RedisCluster(ClusterCommands):
202+
class RedisCluster(RedisClusterCommands):
202203
RedisClusterRequestTTL = 16
203204

204205
PRIMARIES = "primaries"
@@ -212,6 +213,18 @@ class RedisCluster(ClusterCommands):
212213
COMMAND_FLAGS = dict_merge(
213214
list_keys_to_dict(
214215
[
216+
"ACL CAT",
217+
"ACL DELUSER",
218+
"ACL GENPASS",
219+
"ACL GETUSER",
220+
"ACL HELP",
221+
"ACL LIST",
222+
"ACL LOG",
223+
"ACL LOAD",
224+
"ACL SAVE",
225+
"ACL SETUSER",
226+
"ACL USERS",
227+
"ACL WHOAMI",
215228
"CLIENT LIST",
216229
"CLIENT SETNAME",
217230
"CLIENT GETNAME",
@@ -770,6 +783,18 @@ def determine_slot(self, *args):
770783
def reinitialize_caches(self):
771784
self.nodes_manager.initialize()
772785

786+
def get_encoder(self):
787+
"""
788+
Get the connections' encoder
789+
"""
790+
return self.encoder
791+
792+
def get_connection_kwargs(self):
793+
"""
794+
Get the connections' key-word arguments
795+
"""
796+
return self.nodes_manager.connection_kwargs
797+
773798
def _is_nodes_flag(self, target_nodes):
774799
return isinstance(target_nodes, str) and target_nodes in self.node_flags
775800

@@ -1383,7 +1408,8 @@ def initialize(self):
13831408
# isn't a full coverage
13841409
raise RedisClusterException(
13851410
f"All slots are not covered after query all startup_nodes. "
1386-
f"{len(self.slots_cache)} of {REDIS_CLUSTER_HASH_SLOTS} covered..."
1411+
f"{len(self.slots_cache)} of {REDIS_CLUSTER_HASH_SLOTS} "
1412+
f"covered..."
13871413
)
13881414
elif not fully_covered and not self._require_full_coverage:
13891415
# The user set require_full_coverage to False.
@@ -1402,7 +1428,8 @@ def initialize(self):
14021428
"cluster-require-full-coverage configuration to no on "
14031429
"all of the cluster nodes if you wish the cluster to "
14041430
"be able to serve without being fully covered."
1405-
f"{len(self.slots_cache)} of {REDIS_CLUSTER_HASH_SLOTS} covered..."
1431+
f"{len(self.slots_cache)} of {REDIS_CLUSTER_HASH_SLOTS} "
1432+
f"covered..."
14061433
)
14071434

14081435
# Set the tmp variables to the real variables
@@ -1950,8 +1977,8 @@ def block_pipeline_command(func):
19501977

19511978
def inner(*args, **kwargs):
19521979
raise RedisClusterException(
1953-
f"ERROR: Calling pipelined function {func.__name__} is blocked when "
1954-
f"running redis in cluster mode..."
1980+
f"ERROR: Calling pipelined function {func.__name__} is blocked "
1981+
f"when running redis in cluster mode..."
19551982
)
19561983

19571984
return inner

redis/commands/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from .cluster import ClusterCommands
1+
from .cluster import RedisClusterCommands
22
from .core import CoreCommands
33
from .helpers import list_or_args
44
from .parser import CommandsParser
55
from .redismodules import RedisModuleCommands
66
from .sentinel import SentinelCommands
77

88
__all__ = [
9-
"ClusterCommands",
9+
"RedisClusterCommands",
1010
"CommandsParser",
1111
"CoreCommands",
1212
"list_or_args",

0 commit comments

Comments
 (0)