Hashes

Hashes #

19 commands. The hash keyspace is independent from the string keyspace at the same key name.

CmdRWSyntaxReturnsExample → reply
HSETWHSET KEY FIELD VALUE [FIELD VALUE ...]integer fields addedHSET user:1 name ada age 36 → 2
HSETNXWHSETNX KEY FIELD VALUEinteger 1 written, 0 field existsHSETNX user:1 name ada → 0
HGETRHGET KEY FIELDbulk, null if the field is absentHGET user:1 name → ada
HMGETRHMGET KEY FIELD [FIELD ...]array of bulk/nullHMGET user:1 name x → [ada, null]
HMSETWHMSET KEY FIELD VALUE [FIELD VALUE ...]+OKHMSET user:2 name bob → OK
HDELWHDEL KEY FIELD [FIELD ...]integer fields removedHDEL user:1 age → 1
HEXISTSRHEXISTS KEY FIELDinteger 0/1HEXISTS user:1 name → 1
HGETALLRHGETALL KEYarray field/value pairsHGETALL user:1 → [name, ada]
HKEYSRHKEYS KEYarray of fieldsHKEYS user:1 → [name]
HVALSRHVALS KEYarray of valuesHVALS user:1 → [ada]
HLENRHLEN KEYinteger field countHLEN user:1 → 1
HSTRLENRHSTRLEN KEY FIELDinteger value length, 0 if absentHSTRLEN user:1 name → 3
HINCRBYWHINCRBY KEY FIELD incrementinteger new valueHINCRBY stats hits 1 → 1
HKEYEXISTSRHKEYEXISTS KEYinteger 0/1 — does the hash existHKEYEXISTS user:1 → 1
HCLEARWHCLEAR KEYinteger fields removedHCLEAR user:1 → 2
HMCLEARWHMCLEAR KEY [KEY ...]integer hashes removedHMCLEAR a b → 2
HEXPIREWHEXPIRE KEY secondsinteger 1 set, 0 key absentHEXPIRE user:1 300 → 1
HEXPIREATWHEXPIREAT KEY unixTimeinteger 1/0HEXPIREAT user:1 1767225600 → 1
HTTLRHTTL KEYinteger seconds left, -1 noneHTTL user:1 → 299

Notes #

  • HCLEAR / HMCLEAR delete the whole hash (like DEL for this type) and take its expiration with it; HDEL removes individual fields.
  • There is no HPERSIST — the handler exists but is not registered.
  • HSET counts only newly created fields; overwriting an existing field counts 0.
  • HGETALL answers field/value pairs in the storage’s iteration order. Do not rely on it for ordering — sort client-side if it matters.
  • HGET of a field whose value is empty answers an empty bulk string on the local backends and null on the decentralized ones — the two states are not distinguishable there. See Compatibility.
  • HSTRLEN reports 0 both for a missing field and for an empty one.
  • Expiry: HEXPIRE/HEXPIREAT/HTTL act on the hash, independently of any string at the same key.