NEXPIRE
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).
Return value
Section titled “Return value”| 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.
Examples
Section titled “Examples”127.0.0.1:6379> SET lease "worker-3"OK127.0.0.1:6379> NEXPIRE lease 250000000(integer) 1127.0.0.1:6379> PTTL lease(integer) 249127.0.0.1:6379> NEXPIRE missing 1000(integer) 0Compatibility
Section titled “Compatibility”HotKV-only command. Unlike EXPIRE, it does not publish an
expire keyspace event.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.