Introduction
Sets and sorted sets help you keep track of groups of items. You use them to check if something is part of a group quickly.
SADD key member [member ...] SISMEMBER key member ZADD key [NX|XX] [CH] [INCR] score member [score member ...] ZRANK key member
SADD myset apple banana cherry SISMEMBER myset banana
ZADD myzset 10 alice 20 bob 15 carol ZRANK myzset bob
SADD fruits apple banana cherry SISMEMBER fruits banana ZADD leaderboard 100 alice 200 bob 150 carol ZRANK leaderboard bob
myset?SADD adds members to a Set in Redis.ZADD is for Sorted Sets, LPUSH is for Lists, and HSET is for Hashes.SADD fruits apple banana orangeZADD scores 10 alice 20 bob 15 carolfruits?SISMEMBER checks if an item is in a Set.fruits, and we check for 'banana'. So SISMEMBER fruits banana is correct.scores. Which command is incorrect and will cause an error?ZSCORE, ZRANK, and ZREM are valid Sorted Set commands.SISMEMBER is only for Sets, not Sorted Sets, so it will cause an error.leaderboard with player scores. You want to check if a player john exists in the leaderboard and get his rank. Which sequence of commands is correct?ZSCORE returns the score if the member exists, otherwise null.ZRANK returns the rank of the member in the Sorted Set.ZSCORE, then get rank with ZRANK. Using SISMEMBER is invalid for Sorted Sets.Pass the test and this pattern moves unknown