Bird
Raised Fist0
Redisquery~10 mins

SISMEMBER for membership check in Redis - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - SISMEMBER for membership check
Start
↓
Check if element exists in set
Yes No↓
Return 1
↓
End
SISMEMBER checks if a given element is in a Redis set and returns 1 if yes, 0 if no.
Execution Sample
Redis
SADD fruits apple banana cherry
SISMEMBER fruits banana
SISMEMBER fruits orange
Add three fruits to a set, then check if 'banana' and 'orange' are members.
Execution Table
StepCommandSet ContentElement CheckedResultExplanation
1SADD fruits apple banana cherryapple, banana, cherry--Add elements to set 'fruits'
2SISMEMBER fruits bananaapple, banana, cherrybanana1'banana' is in the set, returns 1
3SISMEMBER fruits orangeapple, banana, cherryorange0'orange' not in set, returns 0
💡 All commands executed; membership checks returned 1 or 0 accordingly.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3
fruits setemptyapple, banana, cherryapple, banana, cherryapple, banana, cherry
SISMEMBER resultN/AN/A10
Key Moments - 2 Insights
Why does SISMEMBER return 1 for 'banana' but 0 for 'orange'?
Because 'banana' was added to the set in step 1 (see execution_table row 1), so SISMEMBER finds it and returns 1. 'orange' was never added, so it returns 0 (see row 3).
Does SISMEMBER change the set contents?
No, SISMEMBER only checks membership and does not modify the set. The set remains the same after membership checks (see variable_tracker for 'fruits set').
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of SISMEMBER checking 'banana'?
A-1
B0
C1
DError
💡 Hint
Check execution_table row 2 under 'Result' column.
At which step does the set 'fruits' get its elements added?
AStep 2
BStep 1
CStep 3
DNo step adds elements
💡 Hint
Look at execution_table row 1 where SADD command is executed.
If we check SISMEMBER for 'apple' after step 3, what would the result be?
A1
B0
CError
DDepends on previous commands
💡 Hint
Refer to variable_tracker showing 'apple' is in the set after step 1 and no changes after.
Concept Snapshot
SISMEMBER key element
- Checks if 'element' is in the set stored at 'key'
- Returns 1 if present, 0 if not
- Does not modify the set
- Useful for quick membership tests in Redis sets
Full Transcript
This visual execution shows how the Redis command SISMEMBER works. First, elements 'apple', 'banana', and 'cherry' are added to the set 'fruits' using SADD. Then, SISMEMBER checks if 'banana' is in the set and returns 1 because it is present. Next, it checks for 'orange' and returns 0 because 'orange' was never added. The set remains unchanged during membership checks. This helps understand how SISMEMBER quickly tells if an element is part of a Redis set without changing data.

Practice

(1/5)
1. What does the Redis command SISMEMBER do?
easy
A. Adds a value to a set
B. Removes a value from a set
C. Checks if a value is a member of a set and returns 1 or 0
D. Returns all members of a set

Solution

  1. Step 1: Understand SISMEMBER purpose

    The SISMEMBER command checks membership of a value in a Redis set.
  2. Step 2: Identify return values

    It returns 1 if the value is in the set, otherwise 0.
  3. Final Answer:

    Checks if a value is a member of a set and returns 1 or 0 -> Option C
  4. Quick Check:

    SISMEMBER returns 1 or 0 [OK]
Hint: SISMEMBER returns 1 if present, else 0 [OK]
Common Mistakes:
  • Confusing SISMEMBER with SADD or SREM
  • Expecting SISMEMBER to return the value itself
  • Thinking SISMEMBER returns all set members
2. Which of the following is the correct syntax to check if 'apple' is in the set 'fruits' using Redis?
easy
A. SISMEMBER(fruits, apple)
B. SISMEMBER 'fruits' 'apple'
C. SISMEMBER fruits, apple
D. SISMEMBER fruits apple

Solution

  1. Step 1: Recall Redis command syntax

    Redis commands use space-separated arguments without commas or parentheses.
  2. Step 2: Match correct syntax

    Correct syntax is SISMEMBER key member, so SISMEMBER fruits apple is correct.
  3. Final Answer:

    SISMEMBER fruits apple -> Option D
  4. Quick Check:

    Redis commands use spaces, no commas or quotes needed [OK]
Hint: Use space-separated arguments without quotes or commas [OK]
Common Mistakes:
  • Adding commas between arguments
  • Using parentheses like a function call
  • Adding quotes around arguments unnecessarily
3. Given the Redis set 'colors' contains {"red", "blue", "green"}, what is the output of SISMEMBER colors yellow?
medium
A. 0
B. 1
C. red
D. Error

Solution

  1. Step 1: Check if 'yellow' is in the set 'colors'

    The set contains "red", "blue", and "green" but not "yellow".
  2. Step 2: Understand SISMEMBER return value

    SISMEMBER returns 1 if member exists, else 0. Since "yellow" is not in the set, it returns 0.
  3. Final Answer:

    0 -> Option A
  4. Quick Check:

    Member absent = 0 [OK]
Hint: If value not in set, SISMEMBER returns 0 [OK]
Common Mistakes:
  • Assuming it returns the value itself
  • Confusing 0 with an error
  • Thinking it returns the whole set
4. You run the command SISMEMBER colors without specifying a member. What will happen?
medium
A. Syntax error
B. Returns 1
C. Returns 0
D. Returns all members

Solution

  1. Step 1: Check command argument requirements

    SISMEMBER requires exactly two arguments: the set key and the member to check.
  2. Step 2: Analyze missing argument effect

    Omitting the member argument causes a syntax error in Redis.
  3. Final Answer:

    Syntax error -> Option A
  4. Quick Check:

    Missing arguments cause syntax error [OK]
Hint: SISMEMBER needs two arguments; missing one causes error [OK]
Common Mistakes:
  • Expecting default member to be checked
  • Thinking it returns 0 if member missing
  • Assuming it returns all members
5. You have a Redis set 'users' with members {"alice", "bob", "carol"}. You want to check if 'dave' is a member and add him only if he is not already present. Which sequence of commands correctly does this?
hard
A. SISMEMBER users dave SREM users dave
B. SISMEMBER users dave SADD users dave
C. SADD users dave SISMEMBER users dave
D. SREM users dave SADD users dave

Solution

  1. Step 1: Check membership before adding

    Use SISMEMBER to see if 'dave' is already in 'users'.
  2. Step 2: Add 'dave' only if not present

    If SISMEMBER returns 0, then use SADD to add 'dave'.
  3. Final Answer:

    SISMEMBER users dave SADD users dave -> Option B
  4. Quick Check:

    Check membership then add if absent [OK]
Hint: Check with SISMEMBER before SADD to avoid duplicates [OK]
Common Mistakes:
  • Adding before checking membership
  • Removing member instead of adding
  • Checking membership after adding
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard