English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Redis 哈希(Hash)

Redis hash è una tabella di mappatura del tipo stringa (campo) e valore (valore), adatto particolarmente per memorizzare oggetti.

Ogni hash in Redis può memorizzare 232 - 1 coppia di chiave-valore (oltre 4 miliardi).

Esempi online

127.0.0.1:6379> HMSET w3codeboxkey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000
OK
127.0.0.1:6379> HGETALL w3codeboxkey
1) "name"
2) "redis tutorial"
3) "description"
4) "redis basic commands for caching"
5) "likes"
6) "20"
7) "visitors"
8) "23000"

Nell'esempio sopra, abbiamo impostato alcune informazioni descrittive di redis (name, description, likes, visitors) nella tabella hash w3codeboxkey .

Comandi hash Redis

La tabella seguente elenca i comandi base relativi a redis hash:

Numero di sequenzaComando e descrizione
1HDEL key field1 [field2]
Elimina uno o più campi della tabella hash
2HEXISTS key field
Verifica l'esistenza del campo specificato nella tabella hash key.
3HGET key field
Ottieni il valore del campo specificato memorizzato nella tabella hash.
4HGETALL key
获取在哈希表中指定 key 的所有字段和值
5HINCRBY key field increment
为哈希表 key 中的指定字段的整数值加上增量 increment 。
6HINCRBYFLOAT key field increment
为哈希表 key 中的指定字段的浮点数值加上增量 increment 。
7HKEYS key
获取所有哈希表中的字段
8HLEN key
获取哈希表中字段的数量
9HMGET key field1 [field2]
获取所有给定字段的值
10HMSET key field1 value1 [field2 value2 ]
同时将多个 field-value (域-值)对设置到哈希表 key 中。
11HSET key field value
将哈希表 key 中的字段 field 的值设为 value 。
12HSETNX key field value
只有在字段 field 不存在时,设置哈希表字段的值。
13HVALS key
获取哈希表中所有值。
14HSCAN key cursor [MATCH pattern] [COUNT count]
迭代哈希表中的键值对。

更多命令请参考:https://redis.io/commands