hexpire.3valkey - Man Page
Sets the expiration time of one or more hash fields in seconds.
Synopsis
HEXPIRE key seconds [NX | [XX] [GT | LT]] FIELDS numfields field [field...]
Description
The HEXPIRE command allows manipulating the expiration time for existing hash fields. When set, the expiration time of a hash field will determine when the field will be automatically deleted. Note, that providing a millisecond time of `0' will cause immediate expiration and deletion of the field(s).
Options
The HEXPIRE command supports a set of options that modify its behavior:
- 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.
Reply
Array of integer codes indicating the result of setting expiry on each specified field, in the same order as the fields are requested.
- -2: Field does not exist in the HASH, or key does not exist.
- 0: The specified NX | XX | GT | LT condition has not been met.
- 1: The expiration time was applied.
- 2: When called with 0 seconds.
Complexity
O(N) where N is the number of specified fields.
Acl Categories
@fast @hash @write
History
- Available since: 9.0.0
Examples
127.0.0.1:6379> HSET myhash f1 v1 f2 v2 f3 v3 (integer) 3 127.0.0.1:6379> HEXPIRE myhash 10 FIELDS 2 f2 f3 1) (integer) 1 2) (integer) 1 127.0.0.1:6379> HTTL myhash FIELDS 3 f1 f2 f3 1) (integer) -1 2) (integer) 8 3) (integer) 8
See Also
hdel(3valkey), hexists(3valkey), hexpireat(3valkey), hexpiretime(3valkey), hget(3valkey), hgetall(3valkey), hgetdel(3valkey), hgetex(3valkey), hincrby(3valkey), hincrbyfloat(3valkey), hkeys(3valkey), hlen(3valkey), hmget(3valkey), hmset(3valkey), hpersist(3valkey), hpexpire(3valkey), hpexpireat(3valkey), hpexpiretime(3valkey), hpttl(3valkey), hrandfield(3valkey), hscan(3valkey), hset(3valkey), hsetex(3valkey), hsetnx(3valkey), hstrlen(3valkey), httl(3valkey), hvals(3valkey)