Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

NEXPIRE

Last updated
NEXPIRE key nanoseconds
Group
Keys
Complexity
O(1)
Arity
3 (exactly, counting the command name)
Flags
write, fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

NEXPIRE makes key expire after the given number of nanoseconds. Use it when millisecond precision (PEXPIRE) is too coarse, for example for very short-lived locks or sub-millisecond rate windows. Read the remaining time back with NTTL.

NEXPIRE takes no NX, XX, GT or LT options: it always replaces the key’s current time to live. A value of zero or less makes the key expire at once (the reply is still 1).

Case RESP2 RESP3
The time was set Integer 1 Integer 1
The key does not exist Integer 0 Integer 0

ERR value is not an integer or out of range when nanoseconds is not a 64-bit integer.

127.0.0.1:6379> SET lease "worker-3"
OK
127.0.0.1:6379> NEXPIRE lease 250000000
(integer) 1
127.0.0.1:6379> PTTL lease
(integer) 249
127.0.0.1:6379> NEXPIRE missing 1000
(integer) 0

HotKV-only command. Unlike EXPIRE, it does not publish an expire keyspace event.

NEXPIREAT, NTTL, PEXPIRE, EXPIRE