我在本地桌面或远程测试服务器上使用redis服务器。
我想在Redis服务器上不存在时设置密钥。
所以我检查密钥是否存在,请按照以下代码
let pool;
// Redis Connect
export const connect = async () => {
try {
if (!pool) {
pool = await redis.createClient({
host: RedisConf.connect.name,
port: RedisConf.connect.port,
db: 0
});
}
} catch (err) {
console.log(`Redis Connect Error - ${err}`);
}
return pool;
};
export const exists = async pKey => {
const rds = await connect();
let existsResult;
try {
existsResult = await rds.exists(pKey);
console.log(existsResult);
} catch (err) {
console.log(`Exists Command Error - `, err);
}
return existsResult;
};
### using above code on my custom middleware module
// is write in side of async function
const redisKey = `${RedisConf.keyName.app}:${authKey}`;
// Check Is In Redis Server
let isRedisExists = await RedisUtil.exists(redisKey);
isRedisExists = Boolean(isRedisExists);
console.log(`isRedisExists => ${isRedisExists} => ${!isRedisExists}`);
try {
if (!isRedisExists) {
console.log(`redis Set Process => start`);
// Do something
]
}catch(err){
// Do something
}
github问题:https://github.com/NodeRedis/node_redis/issues/1400#issue-389113321
我该如何解决以上问题?