0
0
Redisquery~5 mins

SRANDMEMBER for random elements in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Redis command SRANDMEMBER do?
It returns one or more random elements from a set stored at a given key without removing them.
Click to reveal answer
beginner
How do you get exactly 3 random elements from a Redis set using SRANDMEMBER?
Use SRANDMEMBER key 3 where key is your set's name.
Click to reveal answer
intermediate
What happens if you ask SRANDMEMBER for more elements than the set contains?
Redis returns as many unique elements as possible, up to the set size, without duplicates.
Click to reveal answer
intermediate
How can you get random elements with possible duplicates using SRANDMEMBER?
Use a negative count like SRANDMEMBER key -3. This allows duplicates in the result.
Click to reveal answer
beginner
Does SRANDMEMBER remove elements from the set?
No, it only returns random elements without removing them from the set.
Click to reveal answer
What does SRANDMEMBER myset return if myset contains {"apple", "banana", "cherry"}?
ARemoves and returns one element
BAll elements in random order
COne random element from the set
DReturns the size of the set
How do you get 2 random elements from a Redis set named fruits?
ASRANDMEMBER fruits 2
BSRANDMEMBER fruits -2
CSPOP fruits 2
DSMEMBERS fruits 2
What does SRANDMEMBER key -3 do?
AReturns the first 3 elements
BReturns 3 unique random elements
CRemoves 3 elements randomly
DReturns 3 random elements with possible duplicates
If a set has 2 elements and you request 5 unique elements with SRANDMEMBER, what happens?
AReturns 2 unique elements
BReturns 5 elements with duplicates
CReturns an error
DReturns empty
Does SRANDMEMBER change the set contents?
AYes, it removes returned elements
BNo, it only reads random elements
CYes, it adds new elements
DYes, it sorts the set
Explain how to use SRANDMEMBER to get random elements from a Redis set and how the count parameter affects the output.
Think about how you pick random cards from a deck without removing them.
You got /5 concepts.
    Describe the difference between SRANDMEMBER and SPOP in Redis.
    Compare looking at a card vs taking it out of the deck.
    You got /5 concepts.