使用 Redis Expire 命令选项时出错

sac*_*n p 2 redis node.js node-redis redis-cli

如果尚未使用 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)`
Run Code Online (Sandbox Code Playgroud)

我得到的上述回应是

incr val 5

ttl expiry 180

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

谢谢

Lei*_*man 6

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