Description
Returns the values of all specified keys. For every key that does not hold a string value or does not exist, the special valuenull is returned.
Syntax
Parameters
The keys to retrieve. Can be passed as an array or as individual arguments
Type Parameters
An array type representing the expected types of the returned values. Each element can be a specific type or
null if the key doesn’t exist.Returns
An array of values at the specified keys. For keys that don’t exist,
null is returned at that position.Examples
Basic Usage
Using Rest Parameters
Handling Non-Existent Keys
Fetching User Data
Batch Fetching with Type Safety
Configuration Settings
Dynamic Key Fetching
Cache Warming
Performance Considerations
- MGET is more efficient than multiple GET commands because it reduces network round trips
- For fetching many keys, MGET significantly reduces latency compared to sequential GET calls
- The command has O(N) time complexity where N is the number of keys to retrieve
Notes
- The order of values in the result matches the order of keys in the request
- Non-existent keys return
nullat their respective positions - This is an atomic operation
- MGET is significantly faster than multiple GET commands due to reduced network overhead