HPEXPIRE
HPEXPIRE key milliseconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
- Group
- Hash
- Complexity
- O(N) where N is the number of fields given
- Arity
- -6 (at least 6 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
HPEXPIRE works like HEXPIRE, but the time to live is
given in milliseconds. Each listed field of the hash at key is removed when
its time passes, and the key is deleted when its last field goes.
A value of 0 removes the fields at once (result code 2).
Options
Section titled “Options”| Option | Effect |
|---|---|
NX |
Set the TTL only on fields that have none. |
XX |
Set the TTL only on fields that already have one. |
GT |
Set the TTL only if it is later than the field’s current one. A field without a TTL never matches. |
LT |
Set the TTL only if it is earlier than the field’s current one. A field without a TTL always matches. |
Return value
Section titled “Return value”An array with one integer per field, in the order given, under both RESP2 and RESP3:
| Code | Meaning |
|---|---|
-2 |
The field or the key does not exist. |
0 |
The condition was not met; nothing changed. |
1 |
The time to live was set. |
2 |
The time was 0 or already in the past, so the field was deleted. |
The errors are the same as for HEXPIRE, with the command
named hpexpire in ERR invalid expire time in 'hpexpire' command.
Examples
Section titled “Examples”127.0.0.1:6379> HSET cache:7 body "<html>" etag "x1"(integer) 2127.0.0.1:6379> HPEXPIRE cache:7 1500 FIELDS 1 body1) (integer) 1127.0.0.1:6379> HPTTL cache:7 FIELDS 2 body etag1) (integer) 15002) (integer) -1Compatibility
Section titled “Compatibility”Same arguments and per-field result codes as Redis 7.4. Valkey 8 does not have hash field expiration.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.