{
  "id": "msetnx",
  "title": "MSETNX",
  "url": "https://redis.io/docs/latest/commands/msetnx/",
  "summary": "Atomically modifies the string values of one or more keys only when all keys don't exist.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-06-15T09:55:50-04:00",
  "page_type": "content",
  "content_hash": "0706ebfa867f4ff0062fe4b811b5d364ac6e54c4f7a3a65e5433632764f729a2",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.\n\n\n\nSets the given keys to their respective values.\n`MSETNX` will not perform any operation at all even if just a single key already\nexists.\n\nBecause of this semantic `MSETNX` can be used in order to set different keys\nrepresenting different fields of a unique logic object in a way that ensures\nthat either all the fields or none at all are set.\n\n`MSETNX` is atomic, so all given keys are set at once.\nIt is not possible for clients to see that some of the keys were updated while\nothers are unchanged."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key value [key value ...]</code></summary>\n\nOne or more key-value pairs to set. No keys are set if any of them already exists.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "MSETNX key1 \"Hello\" key2 \"there\"\nMSETNX key2 \"new\" key3 \"world\"\nMGET key1 key2 key3"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no key was set (at least one key already existed).\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the keys were set.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no key was set (at least one key already existed).\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the keys were set."
    }
  ],
  "examples": []
}
