Redis – Hashes

  • Post author:
  • Post category:Redis
  • Post comments:0 Comments

Redis Hashes are maps between the string fields and the string values. Hence, they are the perfect data type to represent objects.

In Redis, every hash can store up to more than 4 billion field-value pairs.

Example

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

In the above example, we have set Redis tutorials detail (name, description, likes, visitors) in hash named ‘tutorialspoint’.

Redis Hash Commands

Following table lists some basic commands related to hash.

Sr.NoCommand & Description
1HDEL key field2 [field2]https://adglob.in/blog/redis-hash-hdel-command/
Deletes one or more hash fields.
2HEXISTS key fieldhttps://adglob.in/blog/redis-hash-hexists-command/
Determines whether a hash field exists or not.
3HGET key fieldhttps://adglob.in/blog/redis-hash-hget-command/
Gets the value of a hash field stored at the specified key.
4HGETALL keyhttps://adglob.in/blog/redis-hash-hgetall-command/
Gets all the fields and values stored in a hash at the specified key
5HINCRBY key field incrementhttps://adglob.in/blog/redis-hash-hincrby-command/
Increments the integer value of a hash field by the given number
6HINCRBYFLOAT key field incrementhttps://adglob.in/blog/redis-hash-hincrbyfloat-command/
Increments the float value of a hash field by the given amount
7HKEYS keyhttps://adglob.in/blog/redis-hash-hkeys-command/
Gets all the fields in a hash
8HLEN keyhttps://adglob.in/blog/redis-hash-hlen-command/
Gets the number of fields in a hash
9HMGET key field1 [field2]https://adglob.in/blog/redis-hash-hmget-command/
Gets the values of all the given hash fields
10HMSET key field1 value1 [field2 value2 ]https://adglob.in/blog/redis-hash-hmset-command/
Sets multiple hash fields to multiple values
11HSET key field valuehttps://adglob.in/blog/redis-hash-hset-command/
Sets the string value of a hash field
12HSETNX key field valuehttps://adglob.in/blog/redis-hash-hsetnx-command/
Sets the value of a hash field, only if the field does not exist
13HVALS keyhttps://adglob.in/blog/redis-hash-hvals-command/
Gets all the values in a hash
14HSCAN key cursor [MATCH pattern] [COUNT count]https://adglob.in/blog/redis-hash-hset-command-2/
Incrementally iterates hash fields and associated values

Leave a Reply