Grokzen / redis-py-cluster

Python cluster client for the official redis cluster. Redis 3.0+.
https://redis-py-cluster.readthedocs.io/
MIT License
1.1k stars 316 forks source link

TypeError: unsupported operand type(s) for +: 'int' and 'str' #499

Closed nieweiming closed 2 years ago

nieweiming commented 2 years ago
Traceback (most recent call last):
  File "XXX\Python38\lib\site-packages\rediscluster\client.py", line 555, in execute_command
    return self._execute_command(*args, **kwargs)
  File "XXX\Python38\lib\site-packages\rediscluster\client.py", line 588, in _execute_command
    slot = self._determine_slot(*args)
  File "XXX\Python38\lib\site-packages\rediscluster\client.py", line 486, in _determine_slot
    keys = args[3: 3 + numkeys]
TypeError: unsupported operand type(s) for +: 'int' and 'str'

when i use execute_command and try to execute EVALSHA command, just like:

EVALSHA 1119c244463dce1ac3a19cdd4fda744e15e02cab 2 src.key target.key

in python like:

rds.execute_command("EVALSHA", "1119c244463dce1ac3a19cdd4fda744e15e02cab", "2", "src.key", "target.key")

https://github.com/Grokzen/redis-py-cluster/blob/master/rediscluster/client.py#L486

if command in ['EVAL', 'EVALSHA']:
    numkeys = args[2]
    keys = args[3: 3 + numkeys]
    slots = {self.connection_pool.nodes.keyslot(key) for key in keys}
    if len(slots) != 1:
        raise RedisClusterException("{0} - all keys must map to the same key slot".format(command))
    return slots.pop()

the param "2" pass to args[2] , so numkeys is "2", type of str, then raise this Exception; Is this a bug, or am I wrong?

nieweiming commented 2 years ago

if i pass 2 rather than "2" , is ok. but got another problem, eval/evalsha command keys must be in same slot this https://redis.io/commands/cluster-keyslot helps me!