Skip to main content

HGETEX

Syntax

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

Time complexity: O(N) where N is the number of requested fields

ACL categories: @write, @hash, @fast

Returns the values of one or more hash fields and optionally changes their expiration. Without an expiration option, HGETEX behaves like HMGET and leaves existing field expirations unchanged.

Options

OptionDescription
EX secondsSet a relative expiration in seconds.
PX millisecondsSet a relative expiration in milliseconds.
EXAT unix-time-secondsSet an absolute Unix expiration time in seconds.
PXAT unix-time-millisecondsSet an absolute Unix expiration time in milliseconds.
PERSISTRemove the expiration from the requested fields.

The options are mutually exclusive and must appear before FIELDS. An EX or PX value of 0, or an EXAT or PXAT value in the past, returns the current field values and then deletes those fields. If the last field is deleted, the hash key is also removed.

Dragonfly expiration precision

Dragonfly stores hash-field expiration times with whole-second resolution. PX and PXAT accept millisecond values, but the resulting expiration is quantized to whole-second resolution. Positive values returned by HPEXPIRETIME are therefore multiples of 1000. Expirations more than 2^28 - 1 seconds (about 8.5 years) in the future are rejected.

Return

Array reply: one value for each requested field, in the same order. A missing field, or every field requested from a missing key, is returned as nil.

An error reply is returned if key contains a non-hash value or the arguments are invalid.

Examples

Set a TTL while retrieving fields. A missing field is returned as nil:

dragonfly> HSET session:42 user alice token abc
(integer) 2
dragonfly> HGETEX session:42 EX 600 FIELDS 2 token missing
1) "abc"
2) (nil)

Remove the field expiration with PERSIST:

dragonfly> HSET session:42 token abc
(integer) 1
dragonfly> HGETEX session:42 EX 600 FIELDS 1 token
1) "abc"
dragonfly> HGETEX session:42 PERSIST FIELDS 1 token
1) "abc"
dragonfly> HTTL session:42 FIELDS 1 token
1) (integer) -1

See also

HMGET | HSETEX | HEXPIRE | HTTL | HPEXPIRETIME