4. You run the command SCARD myset but get an error: WRONGTYPE Operation against a key holding the wrong kind of value. What is the most likely cause?
medium
A. myset is not a set but another data type like string or list
B. The key myset does not exist
C. SCARD command is misspelled
D. Redis server is down
Solution
Step 1: Understand the error message
The error indicates the key exists but is not a set type.
Step 2: Identify cause of WRONGTYPE error
SCARD only works on sets; if myset is string or list, this error occurs.
Final Answer:
myset is not a set but another data type like string or list -> Option A
Quick Check:
WRONGTYPE = wrong data type for SCARD [OK]
Hint: WRONGTYPE means key is not a set [OK]
Common Mistakes:
Assuming key does not exist causes this error
Thinking SCARD command spelling causes this error
Ignoring data type mismatch
5. You have two sets in Redis: setA with 3 elements and setB with 4 elements, where 2 elements overlap. You want to find the total number of unique elements across both sets without retrieving all elements. Which Redis command or combination should you use?
hard
A. SCARD setA + SCARD setB
B. SUNIONSTORE tempSet setA setB followed by SCARD tempSet
C. SINTER setA setB
D. SDIFF setA setB
Solution
Step 1: Understand the problem of counting unique elements across two sets