the callback for `CLUSTER GETKEYSINSLOT` does not work in redis 3+
See original GitHub issueHiya,
Here’s some code to illustrate the issue:
>>> from rediscluster import StrictRedisCluster
>>> startup_nodes = [{'host': '127.0.0.1', 'port': 2951}]
>>> rc = StrictRedisCluster(startup_nodes=startup_nodes)
>>> rc.CLUSTER_COMMANDS_RESPONSE_CALLBACKS['CLUSTER GETKEYSINSLOT']
int
>>> rc.execute_command('CLUSTER GETKEYSINSLOT', 601, 2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-2ad54da2b333> in <module>()
----> 1 rc.execute_command('CLUSTER GETKEYSINSLOT', 601, 2)
...
...
...
venv/lib/python3.6/site-packages/redis/client.py in parse_response(self, connection, command_name, **options)
585 response = connection.read_response()
586 if command_name in self.response_callbacks:
--> 587 return self.response_callbacks[command_name](response, **options)
588 return response
589
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
After applying this diff:
(venv) lcarvalh-ld ~/src/redis-py-cluster git:unstable ± ❱❱❱ git diff
diff --git a/rediscluster/client.py b/rediscluster/client.py
index d0258c3..8f77925 100644
--- a/rediscluster/client.py
+++ b/rediscluster/client.py
@@ -108,7 +108,7 @@ class StrictRedisCluster(StrictRedis):
'CLUSTER DELSLOTS': bool_ok,
'CLUSTER FAILOVER': bool_ok,
'CLUSTER FORGET': bool_ok,
- 'CLUSTER GETKEYSINSLOT': int,
+ 'CLUSTER GETKEYSINSLOT': list,
'CLUSTER INFO': parse_info,
'CLUSTER KEYSLOT': int,
'CLUSTER MEET': bool_ok,
The command now returns a list of bytestring keys:
>>> from rediscluster import StrictRedisCluster
>>> startup_nodes = [{'host': '10.136.208.61', 'port': 2951}]
>>> rc = StrictRedisCluster(startup_nodes=startup_nodes)
>>> rc.CLUSTER_COMMANDS_RESPONSE_CALLBACKS['CLUSTER GETKEYSINSLOT']
list
>>> rc.execute_command('CLUSTER GETKEYSINSLOT', 601, 1)
[b'prod.tag_hosts:ROUTER_MT-LD-2']
Happy to submit a PR, but I presume that just a list of raw bytes it not ideal, based on the existence of parse_cluster_nodes
and parse_cluster_slots
. What would you prefer? A simple function that parses each key would satisfy my personal needs (and I’ve subclassed StrictRedisCluster
to do this:
class RedisCluster(StrictRedisCluster):
def __init__(self, *args, **kwargs) -> None:
"""Create a RedisCluster."""
# fix getkeysinslot callback
self.CLUSTER_COMMANDS_RESPONSE_CALLBACKS['CLUSTER GETKEYSINSLOT'] = lambda x: [nativestr(i) for i in x]
super().__init__(*args, **kwargs)
Thanks in advance for looking!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
redis-py-cluster/release-notes.rst at master - GitHub
Python cluster client for the official redis cluster. Redis 3.0+. ... Fixed bug where "from rediscluster import *" would not work correct ...
Read more >redis-py-cluster Documentation - Read the Docs
A working Redis cluster based on version >=3.0.0 is required. ... This host_port_remap feature will not work on the startup_nodes so you ...
Read more >CLUSTER GETKEYSINSLOT - Redis
The command returns an array of keys names stored in the contacted node and hashing to the specified hash slot. The maximum number...
Read more >Redis Cluster for (node redis) not emitting events
I am using node redis library to connect to redis cluster ,followed ... Currently (v4.0.2) - no. github.com/redis/node-redis/issues/1855.
Read more >ioredis - npm
Medis is an open-sourced, beautiful, easy-to-use Redis GUI ... ioredis supports the node.js callback style redis.get("mykey", (err, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Have a look at this commit https://github.com/Grokzen/redis-py-cluster/commit/2cbe4a5ba859571e1acb86f33f202904a4d18cb1 it should clear up everything for your problem. Also there is a nice new method that you can use instead of the execute_command solution.
awesome!! thanks so much