为了实现订单超时功能,准备用redis的延时回调,即:设置set key=订单id,同时设置过期时间,在过期执行的回调函数中做超时处理
现在问题是,我用的node,我找了ioredis这个node操作redis的库,但是没找到那个超时回调的api在哪。。。
有人用过这个吗?或者推荐个其他的库?或者用node做过这个功能,能分享一下怎么做的吗?
现在尝试用redis的发布订阅,但是也没找到怎么设置延时发布
const redis = new Redis({
port: 6379, // Redis port
host: '127.0.0.1', // Redis host
family: 4, // 4 (IPv4) or 6 (IPv6)
password: '',
db: 5,
});
console.log('setTime =', new Date());
redis.on('pmessage', function (pattern, channel, message) {
console.log(`${pattern}client received message on${channel}${message}`);
});
redis.psubscribe('__keyevent@0__:expired', function (err, count) {
const d = count;
console.log(d);
console.log('cbTime=', new Date());
});
调用
expire
方法https://luin.github.io/ioredi...