sachin p
sachin p

Reputation: 73

Error while using Redis Expire command options

I am trying to set expiry on a key if expiry is not already set by using NX option of Expire command.

But I keep getting error from redis-cli, and when I try from code NX option gets ignored.

When I try to use Expire command from redis-cli I get following error

127.0.0.1:6379> expire ns1 500 NX

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

Redis version - v=6.2.6

Also If I try to do it programatically, expire command is ignored. Code below -

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)`

The response I get for above is

incr val 5

ttl expiry 180

Any help to resolve this will be great

thanks

Upvotes: 3

Views: 4002

Answers (1)

Leibale Eidelman
Leibale Eidelman

Reputation: 3184

https://www.redis.io/commands/expire "Starting with Redis version 7.0.0: Added options: NX, XX, GT and LT"

Upvotes: 7

Related Questions