HEXPIRE

Syntax

  1. 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

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