I am trying to get multiple values from Redis using Python .
- Using method redisClient.keys("UniqueID*") method to get list of keys that match pattern such as "UniqueID10", "UniqueID11", "UniqueID13"
- while passing the list of keys to method redisClient.mget([list of keys]) , i am getting the error
mget - all keys must map to the same key slot
Below is the code snippet (Python Library)
import redis
rc = redis.RedisCluster(host,port)
all_keys_list = rc.get_client().keys("UniqueID*")
all_values = rc.get_client().mget(all_keys_list )
Error: mget - all keys must map to the same key slot
- Can this be solved from python using any other method or concurrency.
- Do I have to use slot hashing while putting keys and is it possible that all same keys entry do not land in same slot due to memory constraint of the slot and I will get this issue again.
There are two ways to accomplish getting multiple keys mapped to different slots
You can use curly braces to ensure they all end up on the same slot {UniqueID}10 and {UniqueID}11 will be on the same slot since only the name inside the braces is hashed.
Instead of using MGET use a pipeline being sure to set transaction to False in python