使用 Redis Expire 命令选项时出错

Error while using Redis Expire command options

如果尚未使用 Expire 命令的 NX 选项设置过期,我正在尝试设置密钥的过期。

但是我不断从 redis-cli 中收到错误消息,当我从代码中尝试时,NX 选项被忽略了。

当我尝试从 redis-cli 使用 Expire 命令时,出现以下错误

127.0.0.1:6379> expire ns1 500 NX

(error) ERR wrong number of arguments for 'expire' command

Redis 版本 - v=6.2.6

此外,如果我尝试以编程方式执行此操作,过期命令将被忽略。下面的代码 -

let res = await client.INCRBY('ns1', 5)
console.log('incr val ' + res)
res = await client.EXPIRE('ns1', 60, { 'NX': true }) // this should set expiry
res = await client.EXPIRE('ns1', 180, { 'NX': true }) //this should ignore setting expiry
res = await client.TTL('ns1')console.log('ttl expiry ' + res)`

我得到的以上回复是

incr val 5

ttl expiry 180

任何解决此问题的帮助都会很棒

谢谢

https://www.redis.io/commands/expire “从 Redis 版本 7.0.0 开始:添加选项:NXXXGTLT