在特定时间而不是持续时间使 redis 缓存密钥过期 [英] expire redis cache key at particular hours rather than duration
本文介绍了在特定时间而不是持续时间使 redis 缓存密钥过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下图:
client.set(name, data, 'EX', 23 * 60 * 60, (err, reply) => {
});
它的作用是将键值存储 23 小时.但是有什么办法可以设置密钥在晚上 11 点 59 分到期?在晚上?
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 本身不提供此功能.但是你可以计算到午夜的秒数.
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);
这篇关于在特定时间而不是持续时间使 redis 缓存密钥过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文