{
  "schema_version": 2,
  "id": "commands/zrandmember",
  "title": "ZRANDMEMBER",
  "url": "https://redis.io/docs/latest/commands/zrandmember/",
  "summary": "Returns one or more random members from a sorted set.",
  "since": "6.2.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:43+01:00",
  "page_type": "content",
  "content_hash": "1b0a6b746ba2fdd44fe9397f486dec74598c2e629c40a9e61aece9d6133a226d",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "When called with just the `key` argument, return a random element from the sorted set value stored at `key`.\n\nIf the provided `count` argument is positive, return an array of distinct elements.\nThe array's length is either `count` or the sorted set's cardinality ([`ZCARD`](https://redis.io/docs/latest/commands/zcard)), whichever is lower.\n\nIf called with a negative `count`, the behavior changes and the command is allowed to return the same element multiple times.\nIn this case, the number of returned elements is the absolute value of the specified `count`.\n\nThe optional `WITHSCORES` modifier changes the reply so it includes the respective scores of the randomly selected elements from the sorted set."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the sorted set.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>count</code></summary>\n\nThe number of members to return. A positive `count` returns up to that many distinct members; a negative `count` returns exactly `|count|` members and may repeat them.\n\n</details>\n\n<details open><summary><code>WITHSCORES</code></summary>\n\nAlso return the score of each returned member. Can only be used together with `count`.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> ZADD dadi 1 uno 2 due 3 tre 4 quattro 5 cinque 6 sei\n(integer) 6\nredis> ZRANDMEMBER dadi\nredis> ZRANDMEMBER dadi\nredis> ZRANDMEMBER dadi -5 WITHSCORES"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": ""
    },
    {
      "id": "specification-of-the-behavior-when-count-is-passed",
      "title": "Specification of the behavior when count is passed",
      "role": "content",
      "text": "When the `count` argument is a positive value this command behaves as follows:\n\n* No repeated elements are returned.\n* If `count` is bigger than the cardinality of the sorted set, the command will only return the whole sorted set without additional elements.\n* The order of elements in the reply is not truly random, so it is up to the client to shuffle them if needed.\n\nWhen the `count` is a negative value, the behavior changes as follows:\n\n* Repeating elements are possible.\n* Exactly `count` elements, or an empty array if the sorted set is empty (non-existing key), are always returned.\n* The order of elements in the reply is truly random."
    },
    {
      "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\n[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): without the additional _count_ argument, the command returns a randomly selected member, or [Nil reply](../../develop/reference/protocol-spec#bulk-strings) when _key_ doesn't exist.\n[Array reply](../../develop/reference/protocol-spec#arrays): when the additional _count_ argument is passed, the command returns an array of members, or an empty array when _key_ doesn't exist. If the _WITHSCORES_ modifier is used, the reply is a list of members and their scores from the sorted set.\n\n**RESP3:**\n\n[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): without the additional _count_ argument, the command returns a randomly selected member, or [Null reply](../../develop/reference/protocol-spec#nulls) when _key_ doesn't exist.\n[Array reply](../../develop/reference/protocol-spec#arrays): when the additional _count_ argument is passed, the command returns an array of members, or an empty array when _key_ doesn't exist. If the _WITHSCORES_ modifier is used, the reply is a list of members and their scores from the sorted set."
    }
  ],
  "examples": []
}
