Skip to content

Commit 0456f66

Browse files
committed
Added **kwargs to Redis' non key-based commands so they could be reused with target_nodes key word in RedisCluster. Removed duplicated commands from commands/cluster.py.
1 parent 39f42d1 commit 0456f66

File tree

7 files changed

+262
-1055
lines changed

7 files changed

+262
-1055
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
@@ -920,6 +920,18 @@ def __init__(self, host='localhost', port=6379,
920920
def __repr__(self):
921921
return "%s<%s>" % (type(self).__name__, repr(self.connection_pool))
922922

923+
def get_encoder(self):
924+
"""
925+
Get the connection pool's encoder
926+
"""
927+
return self.connection_pool.get_encoder()
928+
929+
def get_connection_kwargs(self):
930+
"""
931+
Get the connection's key-word arguments
932+
"""
933+
return self.connection_pool.connection_kwargs
934+
923935
def set_response_callback(self, command, callback):
924936
"Set a custom Response Callback"
925937
self.response_callbacks[command] = callback

redis/cluster.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from collections import OrderedDict
1010
from redis.client import CaseInsensitiveDict, Redis, PubSub
1111
from redis.commands import (
12-
ClusterCommands,
12+
RedisClusterCommands,
1313
CommandsParser
1414
)
1515
from redis.connection import DefaultParser, ConnectionPool, Encoder, parse_url
@@ -201,7 +201,7 @@ class ClusterParser(DefaultParser):
201201
})
202202

203203

204-
class RedisCluster(ClusterCommands, object):
204+
class RedisCluster(RedisClusterCommands, object):
205205
RedisClusterRequestTTL = 16
206206

207207
PRIMARIES = "primaries"
@@ -789,6 +789,18 @@ def determine_slot(self, *args):
789789
def reinitialize_caches(self):
790790
self.nodes_manager.initialize()
791791

792+
def get_encoder(self):
793+
"""
794+
Get the connections' encoder
795+
"""
796+
return self.encoder
797+
798+
def get_connection_kwargs(self):
799+
"""
800+
Get the connections' key-word arguments
801+
"""
802+
return self.nodes_manager.connection_kwargs
803+
792804
def _is_nodes_flag(self, target_nodes):
793805
return isinstance(target_nodes, str) \
794806
and target_nodes in self.node_flags

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)