0
0
Redisquery~10 mins

ZSCORE for member score in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - ZSCORE for member score
Start: Have Sorted Set with members and scores
Call ZSCORE with key and member
Check if member exists in Sorted Set
End
This flow shows how ZSCORE checks if a member exists in a sorted set and returns its score or nil if not found.
Execution Sample
Redis
ZADD leaderboard 100 "Alice"
ZADD leaderboard 150 "Bob"
ZSCORE leaderboard "Alice"
Add two members with scores to a sorted set, then get the score of member "Alice".
Execution Table
StepCommandInputCheck Member Exists?ResultOutput
1ZADDleaderboard 100 "Alice"N/AAdds Alice with score 1001
2ZADDleaderboard 150 "Bob"N/AAdds Bob with score 1501
3ZSCOREleaderboard "Alice"YesAlice found"100"
4ZSCOREleaderboard "Charlie"NoCharlie not foundnil
💡 ZSCORE returns the score if member exists; otherwise returns nil.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
leaderboardempty{"Alice":100}{"Alice":100, "Bob":150}{"Alice":100, "Bob":150}{"Alice":100, "Bob":150}
ZSCORE outputN/AN/AN/A"100"nil
Key Moments - 2 Insights
Why does ZSCORE return nil for a member not in the sorted set?
Because the member does not exist in the sorted set, ZSCORE returns nil to indicate absence, as shown in execution_table row 4.
Is the score returned by ZSCORE a number or a string?
ZSCORE returns the score as a string, not a number. For example, in row 3, the output is "100" (a string).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output of ZSCORE for member "Alice" at step 3?
A100
Bnil
C"100"
D"Alice"
💡 Hint
Check the Output column in execution_table row 3.
At which step does the sorted set contain both "Alice" and "Bob"?
AAfter Step 2
BAfter Step 1
CAfter Step 3
DAfter Step 4
💡 Hint
Look at variable_tracker for 'leaderboard' after each step.
If you call ZSCORE for a member not in the set, what will the output be?
A"0"
Bnil
C"" (empty string)
DAn error message
💡 Hint
See execution_table row 4 Output column.
Concept Snapshot
ZSCORE key member
Returns the score of member in sorted set key as a string.
If member not found, returns nil.
Used to get exact score of a member.
Example: ZSCORE leaderboard "Alice" -> "100"
Full Transcript
This visual execution trace shows how the Redis command ZSCORE works. First, members with scores are added to a sorted set using ZADD. Then, ZSCORE is called with the sorted set key and a member name. If the member exists, ZSCORE returns the score as a string. If the member does not exist, it returns nil. The execution table shows each step, the commands run, checks for member existence, and the output. The variable tracker shows how the sorted set changes after each command. Key moments clarify common confusions such as why nil is returned for missing members and the data type of the returned score. The quiz tests understanding of outputs and state changes. The snapshot summarizes the command usage and behavior.