content/commands/vrandmember.md
Return one or more random elements from a vector set.
The behavior is similar to the SRANDMEMBER command:
null if no count is given, or an empty array if a count is provided.VADD vset VALUES 3 1 0 0 elem1
VADD vset VALUES 3 0 1 0 elem2
VADD vset VALUES 3 0 0 1 elem3
Return a single random element:
VRANDMEMBER vset
"elem2"
Return two distinct random elements:
VRANDMEMBER vset 2
1) "elem1"
2) "elem3"
Return 3 random elements with possible duplicates:
VRANDMEMBER vset -3
1) "elem2"
2) "elem2"
3) "elem1"
Request more elements than exist in the set:
VRANDMEMBER vset 10
1) "elem1"
2) "elem2"
3) "elem3"
When the key doesn't exist:
VRANDMEMBER nonexistent
(nil)
VRANDMEMBER nonexistent 3
(empty array)
This command is useful for:
Internally:
is the name of the key that holds the vector set.
</details>specifies the number of elements to return. Positive values return distinct elements; negative values allow duplicates.
</details>| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Not supported"><nobr>❌ Active-Active</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Not supported"><nobr>❌ Active-Active</nobr></span> | |
{{< multitabs id="vrandmember-return-info" tab1="RESP2" tab2="RESP3" >}}
One of the following:
-tab-sep-
One of the following:
{{< /multitabs >}}