var Redis = require('ioredis');
redis = new Redis();
var key = 'expire_test';
var content ='content'
var timeout = 10;
redis.multi()
.set(key, content)
.expire(key, timeout, function(){
console.log('out');
})
.exec(function(err) {
if(err) {
console.error("Failed to publish EXPIRE EVENT for " + content);
console.error(err);
return;
}
});
like this?
.expire(key, timeout, function(){
console.log('out');
})
The callback of expire will be invoked when the command is queued instead of executed (so that the result of the callback would always be QUEUED). Or you can just set the timeout using the SET command:
redis.set(key, content, 'EX', timeout, function (err, res) {
});
it is a common way with no readability, is it a better way for resolve this problem?
咦?啥问题?为啥需要 callback 呢
终于逼出中文了,哇哈哈,
expire用法基本就2种吧
是想通过 callback 获取到键过期的事件吗
感觉这里callback的一般理解是expire设置成功了没有…
语义上,expire - n秒 - 到期之后回调处理,这样是合理的吧?
所有命令的 callback 值都是命令本身的结果,没有对任何命令做特殊化处理,这样有利于保证语义的统一,也和其他的 redis client 对齐。另外 Redis 没法实现 expire 到期后的通知提醒,所以这个理论上也没法实现。
redis有个键到期提醒…这个?,需要自己新建一个redis订阅连接,单连接好像实现不了,可以玩一下。。不知道跟其他定时任务比怎么样…
这个没法实现到期提醒,只能实现删除提醒。比如 expire 一个键 100 秒过期,Redis 不会恰好在第一百秒删除这个键,而是在下一次访问这个键或者后台垃圾回收时才会真正删除它
大神!👍
ioreis API提供 expire这个方法吗?
同问,redis删除提醒的api有么?某些键过期后想删除一些关联的数据需要用到这个特性
Hey guys, can you explain what's the final behaviour?
redis.set(key, content, 'EX', timeout, function (err, res) {
is this execute right when the key is EXPIRED?
});
The anonymous callback function is executed when the SET command has been completed, not when the key is EXPIRED. I don't believe that there is any notification available to clients when a key has been expired.
No. It will be executed immediately right after the redis handled the command.
Get Outlookhttps://aka.ms/qtex0l for iOS
From: damiano.barbati notifications@github.com
Sent: Tuesday, June 26, 2018 9:37:58 PM
To: luin/ioredis
Cc: 子骅; State change
Subject: Re: [luin/ioredis] how expire key with callback (#163)
Hey guys, can you explain what's the final behaviour?
redis.set(key, content, 'EX', timeout, function (err, res) {
is this execute right when the key is EXPIRED?
});
―
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHubhttps://github.com/luin/ioredis/issues/163#issuecomment-400311660, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAmz_tzv3mUmDt7cAT69g0uYOSj5yRtUks5uAjk2gaJpZM4GFXO7.
Most helpful comment
这个没法实现到期提醒,只能实现删除提醒。比如 expire 一个键 100 秒过期,Redis 不会恰好在第一百秒删除这个键,而是在下一次访问这个键或者后台垃圾回收时才会真正删除它