gpt4 book ai didi

node.js - Node IOREDIS : how to set expire time for a key?

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

我正在使用下面给出的代码连接到 Redis 哨兵

var Redis = require('ioredis');
var redis = new Redis({
sentinels: [{ host: '99.9.999.99', port: 88888 }],
name: 'mymaster'
});

我正在使用以下代码设置键的值:

function (key, data) {

var dataInStringFormat = JSON.stringify(data); /// conbverting obj to string

/// making promise for returning
var promise = new Promise(function (resolve, reject) {
/// set data in redis
redis.set(key, dataInStringFormat)
.then(function (data) {
resolve(data);
}, function (err) {
reject(err);
});
});

return promise;

}

你能帮我提供一个解决方案来设置键值的过期时间吗? 12小时

最佳答案

已记录

redis.set('key', 100, 'ex', 10)

其中 EX10 代表 10 秒。如果要使用毫秒,请将 EX 替换为 PX

关于node.js - Node IOREDIS : how to set expire time for a key?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237001/

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