Skip to main content

HSETEX

Syntax

HSETEX key [NX] seconds field value [field value ...]

Time complexity: O(1) for each field/value pair added, so O(N) to add N field/value pairs when the command is called with multiple field/value pairs.

ACL categories: @read, @hash, @fast

Warning: Experimental! Dragonfly-specific.

Similar to HSET but adds one or more hash fields that expire after specified number of seconds. By default, this command overwrites the values and expirations of specified fields that exist in the hash. If NX option is specified, the field data will not be overwritten. If key doesn't exist, a new key holding a hash is created.

The expiration time can be accessed with the FIELDTTL command.

Return

Integer reply: The number of fields that were added.

Examples

dragonfly> HSETEX myhash 5 field1 "Hello"
(integer) 1
# wait for 4 seconds
dragonfly> HGETALL myhash
1) "field1"
2) "Hello"
# wait for 1 seconds
dragonfly> HGETALL myhash
(empty array)
dragonfly> HSETEX myhash 5 field1 "Hello"
(integer) 1
dragonfly> HSETEX myhash NX 100 field1 "Hello"
(integer) 0
# wait for 5 seconds
dragonfly> HGETALL myhash
(empty array)