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

Hashes command list

CommandsVersionSyntaxDescription
HSET2.0.0key field valueStore a field and value
HDEL2.0.0key field [field ...]Delete a value by field
HGET2.0.0key fieldGet a value by field
HLEN2.0.0keyGet the number of fields
HMSET2.0.0key field value [field value ...]Store multiple fields and values
HMGET2.0.0key field [field ...]Get multiple values
HKEYS2.0.0keyGet all field names of a key
HVALS2.0.0keyGet all values of a key
HGETALL2.0.0keyGet all fields and values of a key
HINCRBY2.0.0key field incrementIncrement or decrement a value by increment
HEXISTS2.0.0key fieldCheck whether a field exists
HSETNX2.0.0key field valueStore only if the field does not already exist
HINCRBYFLOAT2.6.0key field increment_floatIncrement or decrement a value by increment_float
HSCAN2.8.0key cursor [MATCH pattern]
[COUNT count]
Scan fields in batches
HSTRLEN3.2.0key fieldGet the length of a value in bytes

Total : 15


PDF manual


<< ZRANDMEMBER HASHES Introduction HSET >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.