Back to Redis

MSET

content/commands/mset.md

latest1.5 KB
Original Source

{{< note >}} This command's behavior varies in clustered Redis environments. See the [multi-key operations]({{< relref "/develop/using-commands/multi-key-operations" >}}) page for more information. {{< /note >}}

Sets the given keys to their respective values. MSET replaces existing values with new values, just as regular [SET]({{< relref "/commands/set" >}}). See [MSETNX]({{< relref "/commands/msetnx" >}}) if you don't want to overwrite existing values.

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.

Examples

{{% redis-cli %}} MSET key1 "Hello" key2 "World" GET key1 GET key2 {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active</nobr></span> | |

Return information

{{< multitabs id="mset-return-info" tab1="RESP2" tab2="RESP3" >}}

Simple string reply: always OK because MSET can't fail.

-tab-sep-

Simple string reply: always OK because MSET can't fail.

{{< /multitabs >}}