Bird
Raised Fist0
Redisquery~20 mins

Hash slots distribution in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Hash Slots Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Hash slot calculation for a given key
Given the Redis key {user:1000}.data, what is the hash slot number assigned to this key in a Redis cluster?
AThe hash slot is randomly assigned and not related to the key content.
BThe hash slot is calculated on the entire key <code>{user:1000}.data</code> including the braces and suffix.
CThe hash slot is always zero for keys with curly braces.
DThe hash slot is calculated only on the substring inside curly braces, so the slot corresponds to the hash of <code>user:1000</code>.
Attempts:
2 left
💡 Hint
Redis cluster uses the substring inside curly braces to compute the hash slot.
🧠 Conceptual
intermediate
1:30remaining
Purpose of hash slots in Redis cluster
What is the main purpose of hash slots in a Redis cluster?
ATo encrypt data stored in Redis for security.
BTo compress keys to save memory space.
CTo distribute keys evenly across multiple nodes for load balancing.
DTo store keys in a single node only.
Attempts:
2 left
💡 Hint
Think about how Redis cluster manages data across nodes.
📝 Syntax
advanced
1:30remaining
Identify the correct command to view hash slot allocation
Which Redis CLI command correctly shows the hash slot allocation for cluster nodes?
ACLUSTER SLOTS
BCLUSTER INFO
CCLUSTER NODES
DCLUSTER KEYSLOT <key>
Attempts:
2 left
💡 Hint
The command should show slot ranges assigned to nodes.
🔧 Debug
advanced
2:00remaining
Troubleshooting key slot mismatch error
You get a MOVED error when accessing a key in Redis cluster. What is the most likely cause?
AThe client sent the key to the wrong node that does not own the key's hash slot.
BThe key does not exist in the cluster.
CThe key contains invalid characters.
DThe Redis server is down.
Attempts:
2 left
💡 Hint
MOVED errors indicate redirection to the correct node.
❓ optimization
expert
2:30remaining
Optimizing multi-key operations with hash slots
You want to perform a multi-key operation (e.g., MGET) on keys user:1, user:2, and user:3 in a Redis cluster. How should you design the keys to ensure the operation succeeds without errors?
AUse completely different key names without curly braces.
BUse the same hash tag in curly braces for all keys, like <code>{user}:1</code>, <code>{user}:2</code>, <code>{user}:3</code>.
CUse keys with different hash tags, like <code>{user1}:1</code>, <code>{user2}:2</code>, <code>{user3}:3</code>.
DUse keys with no hash tags but ensure they are stored on the same node manually.
Attempts:
2 left
💡 Hint
Multi-key commands require keys to be in the same hash slot.

Practice

(1/5)
1. What is the total number of hash slots used by Redis Cluster to distribute data?
easy
A. 16384
B. 1024
C. 65536
D. 2048

Solution

  1. Step 1: Recall Redis Cluster design

    Redis Cluster divides data into hash slots to distribute keys evenly.
  2. Step 2: Identify the number of hash slots

    The standard number of hash slots in Redis Cluster is 16384.
  3. Final Answer:

    16384 -> Option A
  4. Quick Check:

    Redis Cluster uses 16384 hash slots [OK]
Hint: Remember Redis Cluster always uses 16384 slots [OK]
Common Mistakes:
  • Confusing hash slots with number of keys
  • Thinking slots are 1024 or 2048
  • Assuming slots equal to max integer value
2. Which Redis command shows the current distribution of hash slots across cluster nodes?
easy
A. CLUSTER NODES
B. CLUSTER KEYS
C. CLUSTER SLOTS
D. CLUSTER INFO

Solution

  1. Step 1: Understand Redis cluster commands

    Redis provides commands to inspect cluster state and slot distribution.
  2. Step 2: Identify the command for slot distribution

    The CLUSTER SLOTS command returns how hash slots are assigned to nodes.
  3. Final Answer:

    CLUSTER SLOTS -> Option C
  4. Quick Check:

    CLUSTER SLOTS shows slot distribution [OK]
Hint: Use CLUSTER SLOTS to see slot assignments [OK]
Common Mistakes:
  • Using CLUSTER NODES which shows node info but not slots
  • Confusing CLUSTER INFO with slot details
  • Assuming CLUSTER KEYS exists
3. Given a Redis Cluster with 3 nodes and the following slot ranges: Node1: 0-5460, Node2: 5461-10922, Node3: 10923-16383. Which node holds the key with hash slot 7000?
medium
A. None of the above
B. Node1
C. Node3
D. Node2

Solution

  1. Step 1: Understand slot ranges per node

    Node1 covers slots 0 to 5460, Node2 covers 5461 to 10922, Node3 covers 10923 to 16383.
  2. Step 2: Locate slot 7000

    Slot 7000 falls between 5461 and 10922, so it belongs to Node2.
  3. Final Answer:

    Node2 -> Option D
  4. Quick Check:

    7000 is in Node2's slot range [OK]
Hint: Check which node's slot range includes the slot number [OK]
Common Mistakes:
  • Choosing Node1 because 7000 is less than 10922
  • Choosing Node3 by mistake
  • Not checking slot ranges carefully
4. You run CLUSTER SLOTS but get an error: "ERR This instance has cluster support disabled". What is the likely cause?
medium
A. The Redis instance is not running in cluster mode
B. The command syntax is incorrect
C. The cluster has no slots assigned yet
D. The Redis version is too new

Solution

  1. Step 1: Analyze the error message

    The error says cluster support is disabled, meaning the instance is not a cluster node.
  2. Step 2: Understand cluster mode requirement

    Only Redis instances running in cluster mode support CLUSTER SLOTS command.
  3. Final Answer:

    The Redis instance is not running in cluster mode -> Option A
  4. Quick Check:

    Cluster commands need cluster mode enabled [OK]
Hint: Check if Redis is started with cluster enabled [OK]
Common Mistakes:
  • Assuming syntax error causes this
  • Thinking slots are unassigned causes error
  • Blaming Redis version without checking mode
5. In a Redis Cluster, if you want to evenly distribute 16384 hash slots across 4 nodes, which slot range should Node3 handle?
hard
A. 12288 to 16383
B. 8192 to 12287
C. 4096 to 8191
D. 0 to 4095

Solution

  1. Step 1: Calculate slots per node

    16384 slots divided by 4 nodes = 4096 slots per node.
  2. Step 2: Determine Node3's slot range

    Node1: 0-4095, Node2: 4096-8191, Node3: 8192-12287, Node4: 12288-16383.
  3. Final Answer:

    8192 to 12287 -> Option B
  4. Quick Check:

    Each node gets 4096 slots; Node3 starts at 8192 [OK]
Hint: Divide 16384 by nodes, assign consecutive ranges [OK]
Common Mistakes:
  • Off-by-one errors in slot ranges
  • Assigning wrong ranges to nodes
  • Not dividing slots evenly
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