w3resource

Redis String: MGET

Redis MGET Command

Redis MGET command is used to get the values of all specified keys. For every key that does not hold a string value or does not exist, the special value nil is returned.

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

  • Batch Retrieval: Fetch multiple key values simultaneously to reduce round-trip time.
  • Cache Retrieval: Efficiently access multiple cached values at once.
  • Data Aggregation: Gather related pieces of data stored under different keys.
  • Session Management: Retrieve data for multiple sessions in a single command.
  • Monitoring and Debugging: Quickly inspect the values of several keys for debugging purposes.

Syntax:

MGET KEY1 KEY2 .. KEYN

Available since

1.0.0.

Return Value

Array, a list of values at the specified keys.

Return Value Type

Array

Example: Redis MGET

redis 127.0.0.1:6379> SET key1 "hello"
OK
redis 127.0.0.1:6379> SET key2 "world"
OK
redis 127.0.0.1:6379> MGET key1 key2 someOtherKey
1) "Hello"
2) "World"
3) (nil)

Previous: GETBIT
Next: SETBIT



Follow us on Facebook and Twitter for latest update.