Skip to main content

ZRANDMEMBER

Syntax

ZRANDMEMBER key [count [WITHSCORES]]

Module

sortedset

Categories

read slow sortedset

Description

Return a list of length equivalent to count containing random members of the sorted set. If count is negative, repeated elements are allowed. If count is positive, the returned elements will be distinct. WITHSCORES modifies the result to include scores in the result.

Examples

Get a random member from the sorted set:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
members, err := vault.ZRandMember("key", 1, false)

Get 2 unique random members from the sorted set:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
members, err := vault.ZRandMember("key", 2, false)

Get 4 non-unique random members from the sorted set with scores:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
members, err := vault.ZRandMember("key", -4, true)