How to set expiration time for hmset in node redis?
Since, hmset
is deprecated (see this), you can use hset
with expire
using pipeline
.
pipe = client.pipeline()
pipe.hset(key, mapping=your_object).expire(duration_in_sec).execute()
# for example:
pipe.hset(key, mapping={'a': 1, 'b': 2}).expire(900).execute()
Note: Pipeline does not ensure atomicity.
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)