SRANDMEMBER
Syntax
SRANDMEMBER key [count]
Module
setCategories
read set slowDescription
Returns one or more random members from the set without removing them.
Examples
- Go (Embedded)
- CLI
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)
Return one random element from the set:
> SRANDMEMBER key
Return 5 unique random elements from the set:
> SRANDMEMBER key 5
Return 5 random elements from the set allowing duplicates:
> SRANDMEMBER key -5