How to set expiration time for hmset in node redis?

Terry Djony picture Terry Djony · Dec 26, 2018 · Viewed 9.6k times · Source

I used to do client.setex(key, 900, value) for storing single key-value.
But, I want to store an object with expiration time.
I come up with function hmset, but I don't know how to make expiration time.
I want to use it to store the context and the text of current chat in conversation.
Please help

Answer

Itamar Haber picture Itamar Haber · Dec 26, 2018

To expire a Hash (or any other Redis key for that matter), call the EXPIRE command. In your case:

client.hmset(key, ...
client.expire(key, 9000)