Hash Data type in Redis
Redis Hashes are used to store a list of multiple key- value pairs. it is used to map between a string to another string. It can also used to represent as objects.
Basic Command Used in Hash Data Structure in Redis:
- HSET– This command sets the key-value pair in Hash.
- HGET – This command returns the value of a specified key.
- HMGET – This command returns all the key and values present in the Hash table.
- HINCRBY – This command will increase the value of a specified key.
Example:
HMSET user :1 name GFG city Noida State UP Cost 200
(Command 1)
HGET user : 1 city
Output
: Noida
(Command 2)
HGET user:1 Cost
Output:
200
In the above code HMSET command is used to create Hash data structure in Redis. and HGET command is used to get the data of a particular key.
Note: Every Redis Hash can store up to 2 ^32 -1 key-value pairs.
How Redis Stores Hash Data Types?
- Hashes are implemented as key-value stores within Redis.
- A hash can be thought of as a map or dictionary, where a single key maps to multiple field-value pairs.
- Hashes are suitable for storing structured data.
Complete Guide on Redis Data Types with Commands and Storage
Redis is an open-source, in-memory data store that supports various data types: such as String, Sets, Lists, Hashes, etc. to store data according to the needs of the user. These diverse data types make Redis versatile for caching, messaging, real-time analytics, and more.
Different Data Types in Redis
- 1. String Data Type in Redis
- 2. Hash Data type in Redis
- 3. List Data Type in Redis
- 4. Set Data type in Redis:
- 5. Sorted Set in Redis:
- 6. Streams in Redis:
- 7. HyperLogLog in Redis:
- 8. Bitmaps in Redis:
- 9. Bitfields in Redis
- 10. Probabilistic in Redis:
- 11. Geospatial Indexes in Redis:
- 12. Time-Series in Redis
Contact Us