Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 363
sachin p Avatar asked Dec 06 '25 11:12

sachin p


1 Answers

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

like image 75
Leibale Eidelman Avatar answered Dec 08 '25 23:12

Leibale Eidelman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!