{
  "schema_version": 2,
  "id": "commands/zmove",
  "title": "ZMOVE",
  "url": "https://redis.io/docs/latest/commands/zmove/",
  "summary": "Moves highest- or lowest-scoring members, or a score range of members, from one sorted set to another, preserving scores. Deletes the source sorted set if the last member was moved.",
  "since": "8.12.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-11-23T06:19:08-08:00",
  "page_type": "content",
  "content_hash": "1b61282f2f8d0cb081328b59b31cc0e7bae111905728687d7706cc0889042328",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Atomically moves members from the sorted set at `source` to the sorted set at\n`destination`, preserving their scores. Select members by lowest score (`MIN`),\nhighest score (`MAX`), or a score range (`BYSCORE`).\n\nIf a moved member already exists in `destination`, its score is replaced with\nthe source score. Other destination members are retained. Redis creates\n`destination` if needed and deletes `source` when its last member is moved.\nExisting key expiration times are preserved; a newly created destination has no\nexpiration.\n\nWhen both keys name the same sorted set, the command returns null without\niterating over members. If `source` exists and either key holds another type,\nthe command returns a `WRONGTYPE` error before moving any members.\n\nIn Redis Open Source Cluster, both keys must be in the same hash slot.\nUse a shared hash tag, such as `bookmarks:{user:42}` and\n`batch:{user:42}:001`. See [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations).\n\nUse [`BZMOVE`](https://redis.io/docs/latest/commands/bzmove) to wait for members to become\navailable, or [`ZMOVEMEMBER`](https://redis.io/docs/latest/commands/zmovemember) to move named\nmembers, optionally conditioned on their presence in the destination."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>source</code></summary>\n\nThe key of the sorted set to move members from.\n\n</details>\n\n<details open><summary><code>destination</code></summary>\n\nThe key of the sorted set to move members to.\n\n</details>\n\n<details open><summary><code>MIN | MAX | BYSCORE score-min score-max</code></summary>\n\n- `MIN` moves the members with the lowest scores, in ascending score order.\n  Equal scores use ascending lexicographical member order.\n- `MAX` moves the members with the highest scores, in descending score order.\n  Equal scores use descending lexicographical member order.\n- `BYSCORE score-min score-max` moves members whose scores fall within the\n  specified range. Members are moved and returned in ascending score order,\n  with equal scores ordered lexicographically.\n\nWithout `COUNT`, `MIN` and `MAX` move one member, and `BYSCORE` moves all\nmatching members.\n\nScore bounds are inclusive by default. Prefix a bound with `(` to exclude it.\nFor example, `BYSCORE -inf (1700000000` selects scores strictly less than\n`1700000000`. Use `-inf` and `+inf` for unbounded ends of the range.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>COUNT count</code></summary>\n\nMove at most `count` selected members. `count` must be a positive integer.\nZero and negative counts return `ERR count should be greater than 0` before\nany members are moved. There is no offset argument.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Move one member while preserving unrelated destination members:\n\n\nredis> ZADD scores:{example} 1 one 2 two 3 three\n(integer) 3\nredis> ZADD moved:{example} 99 one 100 retained\n(integer) 2\nredis> ZMOVE scores:{example} moved:{example} MIN\n1) 1) \"one\"\n   2) \"1\"\nredis> ZMOVE scores:{example} moved:{example} MAX\n1) 1) \"three\"\n   2) \"3\"\nredis> ZRANGE moved:{example} 0 -1 WITHSCORES\n1) \"one\"\n2) \"1\"\n3) \"three\"\n4) \"3\"\n5) \"retained\"\n6) \"100\"\nredis> ZMOVE scores:{example} moved:{example} MIN COUNT 0\n(error) ERR count should be greater than 0\nredis> ZRANGE scores:{example} 0 -1 WITHSCORES\n1) \"two\"\n2) \"2\"\n\n\nClaim a bounded batch with scores strictly less than a cutoff:\n\n\nredis> ZADD bookmarks:{user:42} 1699999998 bookmark:a 1699999999 bookmark:b 1700000000 bookmark:c\n(integer) 3\nredis> ZMOVE bookmarks:{user:42} batch:{user:42}:001 BYSCORE -inf (1700000000 COUNT 500\n1) 1) \"bookmark:a\"\n   2) \"1699999998\"\n2) 1) \"bookmark:b\"\n   2) \"1699999999\"\nredis> ZRANGE bookmarks:{user:42} 0 -1 WITHSCORES\n1) \"bookmark:c\"\n2) \"1700000000\"\nredis> ZMOVE bookmarks:{user:42} batch:{user:42}:002 BYSCORE -inf (1700000000 COUNT 500\n(nil)"
    },
    {
      "id": "claim-a-batch-for-processing",
      "title": "Claim a batch for processing",
      "role": "content",
      "text": "When scores represent update times, use `BYSCORE` with an exclusive upper bound\nto claim older members. Selection, destination insertion, and source removal\nhappen in one atomic command. Other clients cannot change a selected member's\nscore between the range check and its removal.\n\nGive each consumer batch a separate destination key. Persist the batch, then\ndelete that destination after successful processing. Writers can continue to\nadd or update members in `source`; deleting the batch does not delete those\nlater source updates.\n\n`ZMOVE` does not acknowledge processing or automatically retry failed batches.\nYour application must retain and recover unprocessed destinations. It moves\nonly sorted-set members and scores; values stored under other keys are not\ncopied or snapshotted."
    },
    {
      "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=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</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): an array of\n  two-element member/score arrays, nested even when only one member is moved.\n  Each score is a bulk string. Pairs follow the selected order.\n- [Nil reply](https://redis.io/docs/latest/develop/reference/protocol-spec#null-arrays): no members\n  were moved because `source` does not exist, no scores match, or both keys\n  name the same sorted set.\n\n**RESP3:**\n\nOne of the following:\n\n- [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays): an array of\n  two-element member/score arrays, nested even when only one member is moved.\n  Each score is a double. Pairs follow the selected order.\n- [Null reply](https://redis.io/docs/latest/develop/reference/protocol-spec#nulls): no members\n  were moved because `source` does not exist, no scores match, or both keys\n  name the same sorted set."
    }
  ],
  "examples": []
}
