hgetex.3valkey - Man Page

Get the value of one or more fields of a given hash key, and optionally set their expiration time or time-to-live (TTL).

Synopsis

HGETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] FIELDS numfields field [field...]

Description

The HGETEX command returns the value of one or more fields of a given hash key, and optionally manipulates their expiration time. The command will return an array in the size of the number of requested fields. Without providing any optional flags, this command behaves exactly like a normal valkey-hmget(7) HMGET command.

Options

The HGETEX command supports a set of options that modify its behavior:

Note for the following:

  1. The EX, PX, EXAT, PXAT, and PERSIST options are mutually exclusive.
  2. Providing `0' expiration TTL via EX or PX optional arguments will cause the specified fields to expire immediately and be removed from the hash.
  3. Providing past expiration time via EXAT or PXAT optional arguments will cause the specified fields to expire immediately and be removed from the hash.

Reply

valkey-protocol(7) Array reply: a list of values associated with the given fields, in the same order as they are requested.

Complexity

O(1)

Acl Categories

@fast @hash @write

History

Examples

127.0.0.1:6379> HSET myhash f1 v1 f2 v2 f3 v3
(integer) 3
27.0.0.1:6379> HGETEX myhash EX 10 FIELDS 2 f2 f3
1) "v2"
2) "v3"
127.0.0.1:6379> HTTL myhash FIELDS 3 f1 f2 f3
1) (integer) -1
2) (integer) 8
3) (integer) 8
127.0.0.1:6379> HGETEX myhash EX 0 FIELDS 3 f1 f2 f3 
1) "v1"
2) "v2"
3) "v3"
127.0.0.1:6379> HGETEX myhash FIELDS 3 f1 f2 f3 
1) (nil)
2) (nil)
3) (nil)

See Also

hdel(3valkey), hexists(3valkey), hexpire(3valkey), hexpireat(3valkey), hexpiretime(3valkey), hget(3valkey), hgetall(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)

Info

2025-10-21 9.0.0 Valkey Command Manual