ZRANDMEMBER
Syntax
ZRANDMEMBER key [count [WITHSCORES]]
Module
sortedsetCategories
read slow sortedsetDescription
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
- Go (Embedded)
- CLI
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)
Get a random member from the sorted set:
> ZRANDMEMBER key
Get 2 unique random members from the sorted set:
> ZRANDMEMBER key 2
Get 4 non-unique random members from the sorted set with scores:
> ZRANDMEMBER key -4 WITHSCORES