{
  "schema_version": 2,
  "id": "commands/cf.insertnx",
  "title": "CF.INSERTNX",
  "url": "https://redis.io/docs/latest/commands/cf.insertnx/",
  "summary": "Adds one or more items to a Cuckoo Filter if the items did not exist previously. A filter will be created if it does not exist",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:54+01:00",
  "page_type": "content",
  "content_hash": "9fedb9c6b351adfb04cecdfa463131570700c5dfed4980ff0630a24ffa93ad55",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Adds one or more items to a cuckoo filter if they did not exist previously, allowing the filter to be created with a custom capacity if it does not exist yet.\n\nThis command is similar to [`CF.ADDNX`](https://redis.io/docs/latest/commands/cf.addnx), except that more than one item can be added and capacity can be specified.\n\n<note><b>Notes:</b>\n\n- This command is slower than [`CF.INSERT`](https://redis.io/docs/latest/commands/cf.insert) because it first checks whether each item exists.\n- Since [`CF.EXISTS`](https://redis.io/docs/latest/commands/cf.exists) can result in false positive, `CF.INSERTNX` may not add an item because it is supposedly already exist, which may be wrong.\n    \n</note>"
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nis key name for a cuckoo filter to add items to.\n\nIf `key` does not exist - a new cuckoo filter is created.\n</details>\n\n<details open><summary><code>ITEMS item...</code></summary>\n\nOne or more items to add.\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>CAPACITY capacity</code></summary>\n    \nSpecifies the desired capacity of the new filter, if this filter does not exist yet.\n    \nIf the filter already exists, then this parameter is ignored.\n    \nIf the filter does not exist yet and this parameter is *not* specified, then the filter is created with the module-level default capacity which is 1024.\n\nSee [`CF.RESERVE`](https://redis.io/docs/latest/commands/cf.reserve) for more information on cuckoo filter capacities.\n</details>\n    \n<details open><summary><code>NOCREATE</code></summary>\n  \nIf specified, prevents automatic filter creation if the filter does not exist (Instead, an error is returned).\n    \nThis option is mutually exclusive with `CAPACITY`.\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> CF.INSERTNX cf CAPACITY 1000 ITEMS item1 item2 \n1) (integer) 1\n2) (integer) 1\n\n\n\nredis> CF.INSERTNX cf CAPACITY 1000 ITEMS item1 item2 item3\n1) (integer) 0\n2) (integer) 0\n3) (integer) 1\n\n\n\nredis> CF.INSERTNX cf_new CAPACITY 1000 NOCREATE ITEMS item1 item2 \n(error) ERR not found"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": ""
    },
    {
      "id": "complexity",
      "title": "Complexity",
      "role": "performance",
      "text": "O(n + i), where n is the number of `sub-filters` and i is `maxIterations`.\nAdding items requires up to 2 memory accesses per `sub-filter`.\nBut as the filter fills up, both locations for an item might be full. The filter attempts to `Cuckoo` swap items up to `maxIterations` times."
    },
    {
      "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; Supported</span><br /> | <span title=\"Supported\">&#x2705; Flexible & Annual</span><br /><span title=\"Supported\">&#x2705; Free & Fixed</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays), where each element is an [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `0` when the item's fingerprint already exists in the filter, `1` when the item is added successfully, or `-1` when the item cannot be added because the filter is full.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) when the number of arguments or key type is incorrect, and also when `NOCREATE` is specified and `key` does not exist.\n\n**RESP3:**\n\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays), where each element is an [integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `0` means that the item's fingerprint already exists in the filter, `1` for successfully adding an item, or `-1` when the item cannot be added because the filter is full.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors) when the number of arguments or key type is incorrect, and also when `NOCREATE` is specified and `key` does not exist."
    }
  ],
  "examples": []
}
