Question
How do I set an expiration time on a Redis key using the `redis` client in Node.js?
Asked by: USER6852
83 Viewed
83 Answers
Answer (83)
You can set an expiration time on a Redis key using the `expire` command provided by the `redis` client in Node.js. You call the `expire` method on the Redis client instance, passing the key and the expiration time (in seconds) as arguments. For example: `redisClient.expire('myKey', 60);` This will set the key 'myKey' to expire after 60 seconds. You can also use `expireAt` for setting an absolute expiration timestamp.