Skip to main content

HEXPIRE

Syntax

HEXPIRE key seconds FIELDS numfields field [field field ...]

Time complexity: O(N) where N is the number of arguments to the command

ACL categories: @write, @hash, @fast

Set an expiration (TTL or time to live) on one or more fields of a given hash key. You must specify at least one field. Field(s) will automatically be deleted from the hash key when their TTLs expire.

Return

Array reply:

  • Integer reply: -2 if no such field exists in the provided hash key, or the provided key does not exist.
  • Integer reply: 1 if the expiration time was set/updated.
  • Integer reply: 2 when HEXPIRE is called with 0 seconds.

Simple error reply:

  • If parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range, an error is returned.
  • If the provided key exists but is not a hash, an error is returned.

Examples

dragonfly$> HEXPIRE no-key 20 FIELDS 2 field1 field2
(nil)
dragonfly$> HSET mykey field1 "hello" field2 "world"
(integer 2)
dragonfly$> HEXPIRE mykey 10 FIELDS 3 field1 field2 field3
1) (integer) 1
2) (integer) 1
3) (integer) -2
dragonfly$> HGETALL mykey
(empty array)