w3resource

Redis Hash: HMGET

Redis HMGET Command

Redis HMGET command is used to get the values associated with the specified fields in the hash stored at key. If a field does not exist in redis hash, then nil value is returned.

Here are some common uses and scenarios for the "HMGET" command:

  • Batch Retrieval: Fetch multiple field values in a single operation.
  • Data Access: Access specific pieces of data stored in a hash efficiently.
  • Configuration Retrieval: Retrieve multiple configuration settings stored as fields within a hash.
  • Session Management: Access multiple attributes or data points for a session or user in one command.
  • Performance Optimization: Reduce the number of round-trips to the Redis server by retrieving multiple fields at once.

Syntax:

HMGET KEY_NAME FIELD1...FIELDN   

Available since

2.0.0.

Return Value

Array reply, a list of values associated with the given fields, in the same order as they are requested.

Return Value Type

Integer

Example: Redis HMGET

127.0.0.1:6379> HSET langhash lang1 "PHP"
(integer) 1
127.0.0.1:6379> HSET langhash lang2 "Javascript"
(integer) 1
127.0.0.1:6379> HSET langhash lang3 "Python"
(integer) 1
127.0.0.1:6379> HMGET langhash lang1 lang2 lang3 lang4
1) "PHP"
2) "Javascript"
3) "Python"
4) (nil)

Example: Redis HMGET another example

127.0.0.1:6379> HMSET user-y email [email protected] language English gender Male
OK
127.0.0.1:6379> HMGET user-y email language gender
1) "[email protected]"
2) "English"
3) "Male"

Previous: HLEN
Next: HMSET



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/redis/redis-hmget-key-field1.php