Skip to main content

SRANDMEMBER

Syntax

SRANDMEMBER key [count]

Module

set

Categories

read set slow

Description

Returns one or more random members from the set without removing them.

Examples

Return one random element from the set:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
elements, err := db.SRandMember("key", 1)

Return 5 unique random elements from the set:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
elements, err := db.SRandMember("key", 5)

Return 5 random elements from the set allowing duplicates:

db, err := sugardb.NewSugarDB()
if err != nil {
log.Fatal(err)
}
elements, err := db.SRandMember("key", -5)