HGETEX
HGETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] FIELDS numfields field [field ...]
- Group
- Hash
- Complexity
- O(N) where N is the number of fields given
- Arity
- -5 (at least 5 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
HGETEX returns the values of the listed fields of the hash at key, like
HMGET, and at the same time changes the time to live of
the fields that exist. Without an expiry option it only reads.
The values are read first. If the expiry you give is already in the past, the fields are returned and then deleted (and the key too, if no fields remain).
Options
Section titled “Options”| Option | Effect |
|---|---|
EX seconds |
Expire the fields after this many seconds. |
PX milliseconds |
Expire the fields after this many milliseconds. |
EXAT unix-time-seconds |
Expire the fields at this Unix time, in seconds. |
PXAT unix-time-milliseconds |
Expire the fields at this Unix time, in milliseconds. |
PERSIST |
Remove the fields’ time to live. |
FIELDS numfields field ... |
The fields to read. Required, exactly numfields names. |
Only one of EX, PX, EXAT, PXAT and PERSIST can be given. The options
and the FIELDS block can come in any order after the key. Times must be
non-negative integers.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Array with one entry per field: the value as a bulk string, or nil bulk string if the field does not exist | Array of bulk strings, with null for a missing field |
| Key does not exist | Array of nils, one per field | Array of nulls |
Errors:
WRONGTYPEifkeyholds a value that is not a hash (checked first).ERR Only one of EX, PX, EXAT, PXAT or PERSIST arguments can be specified.ERR value is not an integer or out of rangeorERR invalid expire time, must be >= 0for a bad time.ERR invalid number of fields,ERR wrong number of arguments(fewer names thannumfields),ERR FIELDS keyword specified multiple times,ERR missing FIELDS argument, orERR unknown argument: <arg>.ERR invalid expire time in 'hgetex' commandif the time is too far in the future.
Examples
Section titled “Examples”127.0.0.1:6379> HSET session:9 token "abc" user "42"(integer) 2127.0.0.1:6379> HGETEX session:9 EX 300 FIELDS 2 token nope1) "abc"2) (nil)127.0.0.1:6379> HTTL session:9 FIELDS 1 token1) (integer) 300127.0.0.1:6379> HGETEX session:9 PERSIST FIELDS 1 token1) "abc"127.0.0.1:6379> HTTL session:9 FIELDS 1 token1) (integer) -1Compatibility
Section titled “Compatibility”Same as Redis 8.0. Redis 7.4 and Valkey 8 do not have this command.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.