hashes_intro
HASHES Introduction
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Introduction
Made of fields and values
A Hash consists of multiple fields and values under one key.
One key can store up to 4 billion (4,294,967,295) field/value pairs.
Similarities between a table and a Hash
Hashes are similar to an RDB table in that they consist of fields and values.
Think of the Hash key as the table PK, the field as a column, and the value as the value.
Because the key plays the same role as a PK, one key is like one row of a table.
View diagram
Differences between a table and a Hash
A table usually has a limited number of columns, while a Hash can have about 4 billion fields, which is nearly unlimited.
To add a column to a table you must alter the table first, but a Hash does not need that preparation.
So adding/deleting fields is free. Adding/deleting a field affects only that key.
Command summary
- SET: HSET, HMSET, HSETNX
- GET: HGET, HMGET, HLEN, HKEYS, HVALS, HGETALL, HSTRLEN, HSCAN, HEXISTS
- REM: HDEL
- INCR: HINCRBY, HINCRBYFLOAT
| Commands | Version | Syntax | Description |
|---|---|---|---|
| HSET | 2.0.0 | key field value | Store a field and value |
| HDEL | 2.0.0 | key field [field ...] | Delete a value by field |
| HGET | 2.0.0 | key field | Get a value by field |
| HLEN | 2.0.0 | key | Get the number of fields |
| HMSET | 2.0.0 | key field value [field value ...] | Store multiple fields and values |
| HMGET | 2.0.0 | key field [field ...] | Get multiple values |
| HKEYS | 2.0.0 | key | Get all field names of a key |
| HVALS | 2.0.0 | key | Get all values of a key |
| HGETALL | 2.0.0 | key | Get all fields and values of a key |
| HINCRBY | 2.0.0 | key field increment | Increment or decrement a value by increment |
| HEXISTS | 2.0.0 | key field | Check whether a field exists |
| HSETNX | 2.0.0 | key field value | Store only if the field does not already exist |
| HINCRBYFLOAT | 2.6.0 | key field increment_float | Increment or decrement a value by increment_float |
| HSCAN | 2.8.0 | key cursor [MATCH pattern] [COUNT count] | Scan fields in batches |
| HSTRLEN | 3.2.0 | key field | Get the length of a value in bytes |
Total : 15
PDF manual
| << ZRANDMEMBER | HASHES Introduction | HSET >> |
|---|
