{
  "id": "topk.add",
  "title": "TOPK.ADD",
  "url": "https://redis.io/docs/latest/commands/topk.add/",
  "summary": "Adds an item to a Top-k sketch. Multiple items can be added at the same time.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-09T10:29:34-04:00",
  "page_type": "content",
  "content_hash": "02475d89c72659990615431af92638b2393136c40065078d6da46aaf7692b577",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Adds an item to a Top-k sketch. \nMultiple items can be added at the same time.\nIf an item enters the Top-K sketch, the item that is expelled (if any) is returned.\nThis allows dynamic heavy-hitter detection of items being entered or expelled from Top-K sketch."
    },
    {
      "id": "parameters",
      "title": "Parameters",
      "role": "parameters",
      "text": "* **key**: the name of the sketch where items are added.\n* **item**: the items to be added."
    },
    {
      "id": "example",
      "title": "Example",
      "role": "example",
      "text": "[code example]"
    },
    {
      "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\"><nobr>&#x2705; Flexible & Annual</nobr></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]() of [bulk string replies]() containing either dropped elements or [nil (null bulk string)]().\n* [Simple error reply]() in these cases: incorrect number of arguments or non-existant key.\n\n**RESP3:**\n\nOne of the following:\n\n* [Array]() of [bulk string replies]() containing either dropped elements or [null]().\n* [Simple error reply]() in these cases: incorrect number of arguments, non-existant key, or key of the incorrect type."
    }
  ],
  "examples": [
    {
      "id": "example-ex0",
      "language": "plaintext",
      "code": "redis> TOPK.ADD topk foo bar 42\n1) (nil)\n2) baz\n3) (nil)",
      "section_id": "example"
    }
  ]
}
