My code is as shown below:
client.set(name, data, 'EX', 23 * 60 * 60, (err, reply) => {
});
What it does is , it stores the key-value for 23 hours. But is there any way , through which I can set the key to expire at 11:59 p.m. in the night?
Redis itself doesn't provide this functionality. But you can calculate the value of seconds until midnight.
var nd = new Date().setHours(23,59,59);
var expire = Math.floor((nd-Date.now())/1000);
Despite the accepted answer, you could use EXPIREAT
for that. However, since SET
does not support this as an argument, you'll need two calls in your code.