Working with Hashes
1. Setting Hash Fields
| Command | Description |
|---|---|
HSET key f v [f v ...] | Returns count of new fields |
HMSET key f v ... | DEPRECATED use HSET |
2. Getting Hash Fields
| Command | Returns |
|---|---|
HGET key field | Value or nil |
HMGET key f1 f2 ... | Array (preserves order) |
3. Getting All Fields
| Command | Returns |
|---|---|
HGETALL key | Flat array of f/v pairs |
HKEYS key | Field names only |
HVALS key | Values only |
4. Checking Field Existence
| Command | Returns |
|---|---|
HEXISTS key field | 1 or 0 |
5. Deleting Hash Fields
| Command | Description |
|---|---|
HDEL key f [f ...] | Returns removed field count; deletes hash if empty |
6. Getting Field Count
| Command | Returns |
|---|---|
HLEN key | Number of fields |
7. Setting if Field Not Exists
| Command | Returns |
|---|---|
HSETNX key field value | 1 set, 0 exists |
8. Incrementing Hash Values
| Command | Description |
|---|---|
HINCRBY key field n | Integer increment |
HINCRBYFLOAT key field amt | Float increment |
9. Getting String Length of Field
| Command | Returns |
|---|---|
HSTRLEN key field | Byte length, 0 if missing |
10. Getting Random Fields
| Command | Options |
|---|---|
HRANDFIELD key [count [WITHVALUES]] | +count unique, -count with repetition 6.2+ |
11. Scanning Hash Fields
| Command | Options |
|---|---|
HSCAN key cursor [MATCH p] [COUNT n] [NOVALUES] | NOVALUES returns only fields 7.4+ |
12. Setting Field Expiration
| Command | Description |
|---|---|
HEXPIRE key seconds [NX|XX|GT|LT] FIELDS n f1 ... | Per-field TTL 7.4+ |
HPEXPIRE key ms ... FIELDS n f1 ... | Millisecond resolution |
HEXPIREAT / HPEXPIREAT | Absolute timestamps |
HTTL / HPTTL | Get field TTL |
HPERSIST key FIELDS n f1 ... | Remove field TTL |