gpt4 book ai didi

node.js - redis expireAt 在服务器中没有过期

转载 作者:IT王子 更新时间:2023-10-29 06:10:59 26 4
gpt4 key购买 nike

我正在尝试使 redis 中的 key 自动过期

when=10
unit='seconds'
redisClient.expireat(key,moment().add(when,unit));

在redis cli上键 *我可以看到我设置的 key

> TTL 472962f1-10ad8-4c4d-bc5e-2e38b632f36
(integer) -1
> Exists 472962f1-10ad8-4c4d-bc5e-2e38b632f36
(integer) 1

10 秒后它没有被删除!

我正在抓紧时间,因为我必须分享信息以回应此 key 在此之后将无法使用。

var whenKeyExpire = moment().add(when,unit).format('MM-DD-YYYY hh:mm:ss A')

最佳答案

在您的情况下,您将错误的值传递给 expireat 函数的参数。对于此功能,您必须检查 here .在这个函数中你必须通过 unixtime。因此,对于您的场景,您可以执行以下操作:

var when=10;
var unit="seconds";
redisClient.expireat(key, +new Date(moment().add(when,unit)), function (err, didSetExpiry){
if(err){
console.log("Error occured: " + err);
} else {
console.log("Redis Key Operation is successful");
}
});

希望对您有所帮助。

关于node.js - redis expireAt 在服务器中没有过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44855018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com