I get the deprication warning, that Redis.hmset() is deprecated. Use Redis.hset() instead.
However hset() takes a third parameter and I can’t figure out what name
is supposed to be.
info = {'users': 10, "timestamp": datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')}
r.hmset("myKey", info)
The above works, but this requires a first parameter called name.
r.hset(name, "myKey", info)
4
Answers
You may execute multiple
hset
for eachfield/value
pair inhmset
.hmset(name, mapping)
: given a hash name ("myKey"
) and a dictionary (info
) set all key/value pairs.hset(name, key=None, value=None, mapping=None)
: given a hash name ("myKey"
) a key and a value, set the key/value. Alternatively, given a dictionary (mapping=info
) set all key/value pairs inmapping
.Source: https://redis-py.readthedocs.io/en/stable/
If this does not work, perhaps you need to update the library?
The problem is that you must specify within
hset()
that you are giving it the mapping. In your case:instead of
I was using Redis.hmset() as following:
If you use Redis.hset() the following you will not get warning.
With this usage, we will skip the single key & value adding step and
redis.hset()
will set all of thekey
andvalue
mappings ininfo
tomyKey
.