Skip to main content

Description

Sets the given keys to their respective values. MSET replaces existing values with new values, just as regular SET. MSET is atomic, so all given keys are set at once. It is not possible for clients to see that some of the keys were updated while others are unchanged.

Syntax

Parameters

kv
Record<string, TData>
required
An object where keys are Redis keys and values are the values to set

Type Parameters

TData
type
The type of values being stored. All values in the object should be of the same type.

Returns

result
'OK'
Always returns "OK" when the operation succeeds

Examples

Basic Usage

Setting User Profile Data

Storing Objects

Configuration Initialization

Updating Multiple Counters

Session Data

Batch Cache Population

Feature Flags

Performance Considerations

  • MSET is more efficient than multiple SET commands because it reduces network round trips
  • The operation is atomic - all keys are set simultaneously
  • For setting many keys, MSET significantly reduces latency compared to sequential SET calls
  • Time complexity is O(N) where N is the number of keys to set

Notes

  • MSET is atomic - all keys are set at once
  • Existing values are overwritten
  • Always returns "OK" on success
  • More efficient than multiple SET operations due to reduced network overhead
  • All values in the object are serialized according to the SDK’s serialization settings
  • set - Set the value of a single key
  • mget - Get the values of multiple keys

Redis Documentation

For more information, see the Redis MSET documentation.