HPEXPIRE key milliseconds [NX | XX | GT | LT] FIELDS numfields field [field ...]
@write,
@hash,
@fast,
This command works like HEXPIRE, but the expiration of a field is
specified in milliseconds instead of seconds.
The HPEXPIRE command supports a set of options:
NX -- For each specified field, set expiration only when the field has no expiration.XX -- For each specified field, set expiration only when the field has an existing expiration.GT -- For each specified field, set expiration only when the new expiration is greater than current one.LT -- For each specified field, set expiration only when the new expiration is less than current one.A non-volatile key is treated as an infinite TTL for the purposes of GT and LT.
The NX, XX, GT, and LT options are mutually exclusive.
redis> HSET mykey field1 "hello" field2 "world"
(integer) 2
redis> HPEXPIRE mykey 2000 FIELDS 2 field1 field2
1) (integer) 1
2) (integer) 1
redis> HGETALL mykey
(empty array)
| Redis Enterprise |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard ✅ Active-Active |
✅ Standard ✅ Active-Active |
One of the following:
-2 if no such field exists in the provided hash key, or the provided key does not exist.0 if the specified NX, XX, GT, or LT condition has not been met.1 if the expiration time was set/updated.2 when HEXPIRE or HPEXPIRE is called with 0 seconds or milliseconds, or when HEXPIREAT or HPEXPIREAT is called with a past Unix time in seconds or milliseconds.