How to switch from hmset() to hset() in Redis?

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)

Comparing the hset vs hmset in docs isn’t clear to me.


You may execute multiple hset for each field/value pair in hmset.

r.hset('myKey', 'users', 10)
r.hset('myKey', 'timestamp', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
r.hset('myKey', 'yet-another-field', 'yet-another-value')
  • first parameter is the key name
  • second parameter is the field name
  • third parameter is the value of the field.

Leave a Reply

Your email address will not be published. Required fields are marked *