Which Redis data structure provides the fastest membership check for a single element?
Think about how each data structure stores elements and how that affects lookup speed.
Redis Sets use hash tables, allowing O(1) time complexity for membership checks. Sorted Sets use skip lists and hashes but are optimized for range queries, not membership speed.
Given a Redis Set named fruits containing apple, banana, and cherry, what is the output of the command SISMEMBER fruits banana?
Remember what SISMEMBER returns when the element exists in the set.
SISMEMBER returns 1 if the element is in the set, 0 if not.
Which of the following Redis commands correctly checks if the member user42 exists in the Sorted Set online_users?
Think about which command returns a score or indication of membership for sorted sets.
ZSCORE returns the score of a member if it exists, otherwise nil. SISMEMBER is for sets, not sorted sets. ZRANK returns the rank or nil, which can also indicate membership but is less direct. ZMEMBER is not a valid command.
You need to frequently check if elements exist and also retrieve them in a sorted order by score. Which Redis data structure is best suited?
Consider both membership check speed and the need to keep elements sorted.
Sorted Sets provide ordered elements by score and allow membership checks via commands like ZSCORE. Sets have faster membership checks but no order. Lists and Hashes do not efficiently support both requirements.
You run the command SISMEMBER online_users user42 on a Sorted Set online_users and it returns an error even though user42 exists. Why?
Check command compatibility with data types.
SISMEMBER is designed for Sets only. For Sorted Sets, membership checks require commands like ZSCORE or ZRANK. Using SISMEMBER on a Sorted Set results in a WRONGTYPE error.