{
  "schema_version": 2,
  "id": "commands/vrandmember",
  "title": "VRANDMEMBER",
  "url": "https://redis.io/docs/latest/commands/vrandmember/",
  "summary": "Return one or multiple random members from a vector set.",
  "since": "8.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:47:58+01:00",
  "page_type": "content",
  "content_hash": "67d55377bffedab912a064033c928e0de3700a84c8306ec172654fce07a94f80",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Return one or more random elements from a vector set.\n\nThe behavior is similar to the `SRANDMEMBER` command:\n\n- When called without a count, returns a single element as a bulk string.\n- When called with a positive count, returns up to that many distinct elements (no duplicates).\n- When called with a negative count, returns that many elements, possibly with duplicates.\n- If the count exceeds the number of elements, the entire set is returned.\n- If the key does not exist, the command returns `null` if no count is given, or an empty array if a count is provided.\n\n[code example]\n\nReturn a single random element:\n\n[code example]\n\nReturn two distinct random elements:\n\n[code example]\n\nReturn 3 random elements with possible duplicates:\n\n[code example]\n\nRequest more elements than exist in the set:\n\n[code example]\n\nWhen the key doesn't exist:\n\n[code example]\n\n[code example]\n\nThis command is useful for:\n\n- Sampling elements for testing or training.\n- Generating random queries for performance testing.\n\nInternally:\n\n- For small counts (less than 20% of the set size), a dictionary is used to ensure uniqueness.\n- For large counts (more than 20% of the set size), a linear scan provides faster performance, though results may be less random."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open>\n<summary><code>key</code></summary>\n\nis the name of the key that holds the vector set.\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open>\n<summary><code>count</code></summary>\n\nspecifies the number of elements to return. Positive values return distinct elements; negative values allow duplicates.\n</details>"
    },
    {
      "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=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; 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* [Array reply](../../develop/reference/protocol-spec#arrays) containing the names of count random elements as [strings](../../develop/reference/protocol-spec#simple-strings).\n* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings) (null bulk string) for unknown keys.\n* [Array reply](../../develop/reference/protocol-spec#arrays) (empty array) for unknown keys when a count is specified.\n\n**RESP3:**\n\nOne of the following:\n* [Array reply](../../develop/reference/protocol-spec#arrays) containing the names of *count* random elements as [strings](../../develop/reference/protocol-spec#simple-strings).\n* [Null reply](../../develop/reference/protocol-spec#nulls) for unknown keys.\n* [Array reply](../../develop/reference/protocol-spec#arrays) (empty array) for unknown keys when a count is specified."
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "- [Vector sets](https://redis.io/docs/latest/develop/data-types/vector-sets)"
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "shell",
      "code": "VADD vset VALUES 3 1 0 0 elem1\nVADD vset VALUES 3 0 1 0 elem2\nVADD vset VALUES 3 0 0 1 elem3",
      "section_id": "overview"
    },
    {
      "id": "overview-ex1",
      "language": "shell",
      "code": "VRANDMEMBER vset\n\"elem2\"",
      "section_id": "overview"
    },
    {
      "id": "overview-ex2",
      "language": "shell",
      "code": "VRANDMEMBER vset 2\n1) \"elem1\"\n2) \"elem3\"",
      "section_id": "overview"
    },
    {
      "id": "overview-ex3",
      "language": "shell",
      "code": "VRANDMEMBER vset -3\n1) \"elem2\"\n2) \"elem2\"\n3) \"elem1\"",
      "section_id": "overview"
    },
    {
      "id": "overview-ex4",
      "language": "shell",
      "code": "VRANDMEMBER vset 10\n1) \"elem1\"\n2) \"elem2\"\n3) \"elem3\"",
      "section_id": "overview"
    },
    {
      "id": "overview-ex5",
      "language": "shell",
      "code": "VRANDMEMBER nonexistent\n(nil)",
      "section_id": "overview"
    },
    {
      "id": "overview-ex6",
      "language": "shell",
      "code": "VRANDMEMBER nonexistent 3\n(empty array)",
      "section_id": "overview"
    }
  ]
}
