HGETEX(3valkey)

πŸ“¦ version 9.0.6, in fedora 44

πŸ’– HGETEX πŸ’–

okay bestie, welcome to the Valkey Command Manual ✨ this one's from the valkey section (3), and it's genuinely one of the cutest hash commands out there, no cap πŸŽ€


🌸 NAME 🌸

hgetex β€” grab the value of one or more fields from a given hash key, and optionally set their expiration time or their time-to-live (TTL). like, read and schedule the goodbye in one go πŸ’…


✨ SYNOPSIS ✨

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

πŸ¦‹ DESCRIPTION πŸ¦‹

So the HGETEX command returns the value of one or more fields of a given hash key, and it optionally messes with their expiration time. iconic

It gives you back an array that's the same size as the number of fields you asked for β€” literally one slot per field, bestie, no surprises 🌈

And here's the chill part: if you don't pass any of the optional flags at all, this command behaves exactly like a regular valkey-hmget(7) HMGET command. same energy, same output. periodt πŸ’œ


πŸ’… OPTIONS πŸ’…

HGETEX supports a lil set of options that change how it behaves:

  • EX seconds β€” set the expiration time you want, measured in seconds ⏰
  • PX milliseconds β€” set the expiration time you want, measured in milliseconds 🫢
  • EXAT unix-time-seconds β€” set the exact Unix time at which the fields will expire, in seconds ⭐
  • PXAT unix-time-milliseconds β€” set the exact Unix time at which the fields will expire, in milliseconds ⭐
  • PERSIST β€” remove the expiration time that's attached to the fields πŸ™ˆ
Notes for the following, bestie, read these fr fr:
  1. The EX, PX, EXAT, PXAT, and PERSIST options are mutually exclusive. pick one, okay? not a combo meal πŸ“
  2. Providing a 0' expiration TTL via the EXorPX` optional arguments will cause the specified fields to expire immediately and be removed from the hash. like, gone gone πŸ’€
  3. Providing a past expiration time via the EXAT or PXAT optional arguments will also cause the specified fields to expire immediately and be removed from the hash. same fate, different route 😭

πŸ’Œ REPLY πŸ’Œ

valkey-protocol(7) Array reply: a list of values associated with the given fields, in the same order as they were requested. order matters, bestie, it always does ✨


🧚 COMPLEXITY 🧚

O(N) where N is the number of specified fields. so like, the more fields you ask for, the more work it does β€” math is math πŸ’…


πŸ‘‘ ACL CATEGORIES πŸ‘‘

@fast @hash @write


🌈 HISTORY 🌈

  • Available since: 9.0.0 β€” a fresh baby, a new gen icon πŸŽ€

πŸ“ 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)

like, watch f1 get a -1 (no expiry, living its best life), then everybody gets an EX 0 and suddenly the whole hash is empty. main character exit 🫢


πŸ”₯ 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)


and that's the whole page, bestie πŸ’– this was 9.0.0, dated 2025-10-21, straight from the HGETEX(3valkey) page β€” go forth and expire things responsibly, ily πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from