I have the dictionary that is as follows:
dict1 = {"a":"foo","b":"bar","c":"foobar"}
The keys of dict1 are fields of a key in redis. I want to use hdel to delete those fields in Redis. I was wondering if its possible to send multiple fields at once to redis.
I thought of creating a list of keys from dict1 and passing it to redis.hdel but it doesn't work and I am always returned false. Will appretiate any help/suggestions.
list1 = []
key = "somerediskey"
for k in dict1:
list1.append(k)
data = redis_connection.hdel(key, list1)
The Python redis lib accept an hdel(name, *keys)
, so you should do:
data = redis_connection.hdel(key, *list1)
Also, you don't need to create a list of keys, you can just use dict1.keys()
:
key = "somerediskey"
data = redis_connection.hdel(key, *dict1.keys())
Related docs: http://kushal.fedorapeople.org/redis-py/html/api.html#redis.StrictRedis.hdel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With