Skip to main content

Description

Returns the values of all specified keys. For every key that does not hold a string value or does not exist, the special value null is returned.

Syntax

Parameters

keys
string[] | ...string[]
required
The keys to retrieve. Can be passed as an array or as individual arguments

Type Parameters

TData
type
default:"(string | null)[]"
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

values
TData
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 null at their respective positions
  • This is an atomic operation
  • MGET is significantly faster than multiple GET commands due to reduced network overhead
  • get - Get the value of a single key
  • mset - Set multiple keys to multiple values

Redis Documentation

For more information, see the Redis MGET documentation.