Redis - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Redis Hashes

Redis Hash

shape Description

A Redis hash is a gathering of key esteem sets. Redis Hashes are maps between string fields and string values, so they are utilized for representing the objects. Hashes basically lets the user to map a string field to a string value.This work well for representing objects that might have multiple fields that the user would want be able to access when storing data in Redis. Hashes are also very efficient ways for storing data in Redis since as long hash doesn't have more than one hundred fields in sorting a way that it doesn't end up talking very much space. Because Redis is optimized for hashes.First we have HSET which can be used to set the values of a hash field,then we have HMSET which can set multiple hash field values at the same time. HSET get a particular values of a filed, and a hash and like wise HMGET,which can set multiple hash field  values at the same time. HSET gets a particular  values of a field, and a hash and like wise HMSET, which can set multiple hash fields values at the same time. HEXISTS would check for the existence of a particular field. HINCRBY increments of an integer field by a specified number just as the use INCR on a string to a particular field.

shape Examples

The below example describes the hashes data type. [sql] redis 127.0.0.1:6379> HMSET user:1 username splessons password splessons points 200 OK redis 127.0.0.1:6379> HGETALL user:1 "username" "SPLessons" "password" "SPLessons" "points" "200" [/sql] And HKEYS return all the keys of the fields in the hash.And then likewise, HVALS return returns all the values of the fields in the hash. And actually sored the client data inside of a string and we serialize that data as some JSON data.It could been any serialization format,but we basically packed everything into a string of very simple data structure instead of using a string.This way using a hash and able to divide out the actual user fields into separate keys in this hash. And that's really the thinking behind using hash or serializing something as a string. And just to clarify what this means basically we have this key for our actual hash.This is our hash and then there a field called name of that hash.It has a value of joe and specify the name field to get back the value of the user.

Redis Hashes command

shape Description

Redis hash command describes the basic functionality of the hashes such as
S.NO Command Description
1 Hexists key field Determine wheather a hash field exists or not
2 HDEL key field2 Delete one or more hash fields
3 HGET key field Get the values of a hash fields stored at specified key
4 HINCRBY key field increment Increment the integer values of ahash field by the given number
5 HKEYS key Get all the field in a hash
6 HLEN key Get the number of fields in a hash
7 HMGET key field1 Get the values of all the given hash fields
8 HMSET key field1 value1 Set multiple hash fields to multiple values
9 HVALS key Get all the values in a hash
10 HSCAN key cursor [MATCH pattern] [COUNT count] Incrementally iterate hash fields and associated values
11 HSCAN key cursor [MATCH pattern] [COUNT count] Incrementally iterate hash fields and associated values

Summary

shape Key Points

  • Hashes - Is a gathering of key esteem sets.
  • Redis Hashes Commands - Describes the basic functionality of hashes.