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"}?✗ Incorrect
SRANDMEMBER returns one random element without removing it.
How do you get 2 random elements from a Redis set named
fruits?✗ Incorrect
Use SRANDMEMBER fruits 2 to get 2 unique random elements without removal.
What does
SRANDMEMBER key -3 do?✗ Incorrect
Negative count allows duplicates in the returned random elements.
If a set has 2 elements and you request 5 unique elements with
SRANDMEMBER, what happens?✗ Incorrect
Redis returns as many unique elements as possible, up to the set size.
Does
SRANDMEMBER change the set contents?✗ Incorrect
SRANDMEMBER does not remove or modify 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.