Search code examples
node.jsredischatchatbotnode-redis

How to set expiration time for hmset in node redis?


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


Solution

  • 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)