Hashes, Lists & Sorted Sets — Series 2

Preview — 3 of 10 questions

What does SDIFF set1 set2 return, given set1 = {a, b, c} and set2 = {b, c, d}?

javascript
SADD set1 a b c
SADD set2 b c d

SDIFF set1 set2
1) "a"        -- only "a" is in set1 but not set2

SDIFF set2 set1
1) "d"        -- reversing the arguments gives a different result: only "d"
A{a}
B{d}
C{b, c}
D{a, b, c, d}

Which command retrieves all leaderboard members with a score between 1000 and 2000 (inclusive)?

javascript
ZRANGEBYSCORE leaderboard 1000 2000
1) "carol"
2) "alice"
AZSCORE leaderboard 1000 2000
BZRANGEBYSCORE leaderboard 1000 2000
CZRANGE leaderboard 1000 2000
DZFILTER leaderboard BETWEEN 1000 2000

A user just scored 50 more points. Which command correctly and atomically adds 50 to their existing leaderboard score?

javascript
ZINCRBY leaderboard 50 alice
"1050"   -- alice's new total score, atomically computed server-side
AZSCORE leaderboard alice then ZADD leaderboard <old+50> alice — read-modify-write in application code
BZADD leaderboard INCR alice 50 — argument order is score then member, always
CZINCRBY leaderboard 50 alice — atomically adds 50 to alice's current score (creating alice with score 50 if she wasn't already a member), avoiding the race condition of a separate read-then-write
DSorted sets do not support incrementing; the member must be removed and re-added with the new total

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.