Saturday 11 April 2015

Redis hashes

Redis hash is similar to HashMap in Java.

How to create Hash
HMSET key field1 value1 field2 value2 ... fieldN valueN

127.0.0.1:6379> hmset employee1 name "Hari Krishna" designation "Senior Sofware Engineer" age 26 
OK 
127.0.0.1:6379> hget employee1 name 
"Hari Krishna" 
127.0.0.1:6379> hget employee1 age 
"26" 
 
In the above snippet, hmset creates a hash for employee1, where name mapped to “Hari Krishna”, designation mapped to “Senior Software Engineer” and age mapped to 26. “hget” command is used to get the value of the field.

hget employee1 name
Above statement returns name field of the hash employee1.

hgetall” command is used to get all keys and values of given hash. 


127.0.0.1:6379> hgetall employee1 
1) "name" 
2) "Hari Krishna" 
3) "designation" 
4) "Senior Sofware Engineer" 
5) "age" 
6) "26"
 
Prevoius                                                 Next                                                 Home

No comments:

Post a Comment