How to do it...

To understand how to use the hash data type, take the following steps:

  1. Open a Terminal and connect to Redis with redis-cli.
  2. Now, let's set the information properties of the "Kyoto Ramen" restaurant using the HMSET command:> HMSET "Kyoto Ramen" "address" "801 Mission St, San Jose, CA" "phone" "555-123-6543" "rating" "5.0" 
  1. Use the HMGET command to retrieve values in a hash:> HMGET "Kyoto Ramen" "address" "phone" "rating" 
1) "801 Mission St, San Jose, CA" 
2) "555-123-6543" 
3) "5.0" 
  1. To retrieve the value for a single field, use HGET:> HGET "Kyoto Ramen" "rating" 
  1. To test if a field exists in the hash, use HEXISTS:> HEXISTS "Kyoto Ramen" "phone" (integer) ...

Get Redis 4.x Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.