Hashes #
19 commands. The hash keyspace is independent from the string keyspace at the same key name.
| Cmd | RW | Syntax | Returns | Example → reply |
|---|---|---|---|---|
HSET | W | HSET KEY FIELD VALUE [FIELD VALUE ...] | integer fields added | HSET user:1 name ada age 36 → 2 |
HSETNX | W | HSETNX KEY FIELD VALUE | integer 1 written, 0 field exists | HSETNX user:1 name ada → 0 |
HGET | R | HGET KEY FIELD | bulk, null if the field is absent | HGET user:1 name → ada |
HMGET | R | HMGET KEY FIELD [FIELD ...] | array of bulk/null | HMGET user:1 name x → [ada, null] |
HMSET | W | HMSET KEY FIELD VALUE [FIELD VALUE ...] | +OK | HMSET user:2 name bob → OK |
HDEL | W | HDEL KEY FIELD [FIELD ...] | integer fields removed | HDEL user:1 age → 1 |
HEXISTS | R | HEXISTS KEY FIELD | integer 0/1 | HEXISTS user:1 name → 1 |
HGETALL | R | HGETALL KEY | array field/value pairs | HGETALL user:1 → [name, ada] |
HKEYS | R | HKEYS KEY | array of fields | HKEYS user:1 → [name] |
HVALS | R | HVALS KEY | array of values | HVALS user:1 → [ada] |
HLEN | R | HLEN KEY | integer field count | HLEN user:1 → 1 |
HSTRLEN | R | HSTRLEN KEY FIELD | integer value length, 0 if absent | HSTRLEN user:1 name → 3 |
HINCRBY | W | HINCRBY KEY FIELD increment | integer new value | HINCRBY stats hits 1 → 1 |
HKEYEXISTS | R | HKEYEXISTS KEY | integer 0/1 — does the hash exist | HKEYEXISTS user:1 → 1 |
HCLEAR | W | HCLEAR KEY | integer fields removed | HCLEAR user:1 → 2 |
HMCLEAR | W | HMCLEAR KEY [KEY ...] | integer hashes removed | HMCLEAR a b → 2 |
HEXPIRE | W | HEXPIRE KEY seconds | integer 1 set, 0 key absent | HEXPIRE user:1 300 → 1 |
HEXPIREAT | W | HEXPIREAT KEY unixTime | integer 1/0 | HEXPIREAT user:1 1767225600 → 1 |
HTTL | R | HTTL KEY | integer seconds left, -1 none | HTTL user:1 → 299 |
Notes #
HCLEAR/HMCLEARdelete the whole hash (likeDELfor this type) and take its expiration with it;HDELremoves individual fields.- There is no
HPERSIST— the handler exists but is not registered. HSETcounts only newly created fields; overwriting an existing field counts 0.HGETALLanswers field/value pairs in the storage’s iteration order. Do not rely on it for ordering — sort client-side if it matters.HGETof a field whose value is empty answers an empty bulk string on the local backends andnullon the decentralized ones — the two states are not distinguishable there. See Compatibility.HSTRLENreports 0 both for a missing field and for an empty one.- Expiry:
HEXPIRE/HEXPIREAT/HTTLact on the hash, independently of any string at the same key.