Bird
Raised Fist0
Redisquery~20 mins

Client-side cluster support in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Redis Cluster Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the output of this Redis cluster command?
Consider a Redis cluster with 3 nodes. You run the command CLUSTER NODES. What kind of information does this command return?
Redis
CLUSTER NODES
AThe cluster configuration file contents.
BOnly the master nodes' IP addresses and ports.
CA list of all nodes in the cluster with their IDs, IP addresses, ports, roles, and slot ranges.
DThe current key-value pairs stored in the cluster.
Attempts:
2 left
💡 Hint
Think about what information is needed to understand the cluster topology.
🧠 Conceptual
intermediate
2:00remaining
How does client-side cluster support handle key distribution?
In Redis client-side cluster support, how does the client decide which node to send a command to for a given key?
AThe client calculates the hash slot of the key and sends the command to the node responsible for that slot.
BThe client sends the command to a random node and lets the cluster redirect it.
CThe client always sends commands to the master node only.
DThe client broadcasts the command to all nodes and waits for the first response.
Attempts:
2 left
💡 Hint
Think about how the cluster divides keys among nodes.
📝 Syntax
advanced
2:00remaining
Which Redis command syntax correctly requests a slot migration in a cluster?
You want to migrate slot 1000 from one node to another in a Redis cluster. Which command syntax is correct?
ACLUSTER SETSLOT 1000 MIGRATING <node-id>
BCLUSTER MIGRATE SLOT 1000 TO <node-id>
CCLUSTER SETSLOT MIGRATING 1000 <node-id>
DCLUSTER SLOT MIGRATE 1000 <node-id>
Attempts:
2 left
💡 Hint
Check the official Redis cluster command format for SETSLOT.
❓ optimization
advanced
2:00remaining
How can client-side cluster support reduce redirections during key access?
Which approach best reduces the number of redirections a Redis client experiences when accessing keys in a cluster?
AThe client always queries a random node to get the latest cluster slots mapping before each command.
BThe client caches the cluster slots mapping and updates it only when a MOVED or ASK error occurs.
CThe client sends all commands to the cluster's master node to avoid redirections.
DThe client disables cluster mode and treats the cluster as a single node.
Attempts:
2 left
💡 Hint
Think about how clients can remember cluster topology to avoid unnecessary redirects.
🔧 Debug
expert
2:00remaining
Why does this Redis cluster client command cause a MOVED error?
A client sends the command GET user:123 to a Redis cluster node but receives a MOVED error pointing to another node. What is the most likely cause?
Redis
GET user:123
AThe client sent the command with an invalid syntax.
BThe key user:123 does not exist in the cluster.
CThe cluster is down and cannot process commands.
DThe client has an outdated slots cache and sent the command to the wrong node.
Attempts:
2 left
💡 Hint
Consider what MOVED errors indicate in Redis cluster communication.

Practice

(1/5)
1. What is the main benefit of using client-side cluster support in Redis?
easy
A. It encrypts all data stored in Redis without extra setup.
B. It reduces the size of the Redis database automatically.
C. It merges all cluster nodes into a single server.
D. It allows the client to connect directly to the correct Redis node in the cluster.

Solution

  1. Step 1: Understand client-side cluster support

    Client-side cluster support means the client knows how to talk to the right Redis node directly.
  2. Step 2: Identify the main benefit

    This direct connection helps speed up requests and balances load across nodes.
  3. Final Answer:

    It allows the client to connect directly to the correct Redis node in the cluster. -> Option D
  4. Quick Check:

    Client-side cluster support = direct node connection [OK]
Hint: Client-side cluster means client talks directly to right node [OK]
Common Mistakes:
  • Thinking it reduces database size automatically
  • Confusing encryption with cluster support
  • Believing it merges nodes into one server
2. Which of the following is the correct way to initialize a Redis client with cluster support in code?
easy
A. redis.createClient({ cluster: true, nodes: [...] })
B. redis.connectCluster(nodes)
C. redis.clusterConnect({ nodes: [...] })
D. redis.newClusterClient(nodes)

Solution

  1. Step 1: Recall Redis client cluster initialization syntax

    The standard way is to create a client with cluster option and provide nodes list.
  2. Step 2: Match syntax to options

    redis.createClient({ cluster: true, nodes: [...] }) matches the known syntax: redis.createClient({ cluster: true, nodes: [...] }). Others are invalid method names.
  3. Final Answer:

    redis.createClient({ cluster: true, nodes: [...] }) -> Option A
  4. Quick Check:

    Correct cluster client init = createClient with cluster true [OK]
Hint: Use createClient with cluster:true and nodes array [OK]
Common Mistakes:
  • Using non-existent methods like connectCluster
  • Forgetting to set cluster: true
  • Passing nodes incorrectly
3. Given a Redis cluster with nodes at ports 7000 and 7001, what will the following code do?
const client = redis.createClient({ cluster: true, nodes: [ { port: 7000 }, { port: 7001 } ] });
await client.connect();
await client.set('key1', 'value1');
const val = await client.get('key1');
console.log(val);
medium
A. It will print 'value1' after storing the key in the correct cluster node.
B. It will throw an error because set is not supported in cluster mode.
C. It will print null because the key is not stored.
D. It will connect only to port 7000 and ignore 7001.

Solution

  1. Step 1: Understand cluster client behavior on set/get

    The client connects to multiple nodes and routes commands to the right node based on key hashing.
  2. Step 2: Analyze code flow

    It sets 'key1' with 'value1' and then gets 'key1'. The client handles routing, so get returns 'value1'.
  3. Final Answer:

    It will print 'value1' after storing the key in the correct cluster node. -> Option A
  4. Quick Check:

    Cluster client routes keys correctly = prints value1 [OK]
Hint: Cluster client routes keys, so get returns stored value [OK]
Common Mistakes:
  • Thinking set/get are unsupported in cluster mode
  • Assuming only one node is used
  • Expecting null because of cluster complexity
4. You wrote this code to connect to a Redis cluster but get a connection error:
const client = redis.createClient({ cluster: true, nodes: [ { port: 7000 } ] });
await client.connect();
What is the most likely cause?
medium
A. The client library does not support cluster mode.
B. The port 7000 is incorrect; cluster nodes use port 6379.
C. You need to provide at least two nodes for cluster support.
D. You forgot to set cluster: false in options.

Solution

  1. Step 1: Check cluster node requirements

    For cluster support, the client should know multiple nodes to discover the cluster topology.
  2. Step 2: Analyze given nodes array

    Only one node is provided, so the client cannot properly discover the cluster, causing connection errors.
  3. Final Answer:

    You need to provide at least two nodes for cluster support. -> Option C
  4. Quick Check:

    Cluster client needs multiple nodes to connect [OK]
Hint: Provide multiple nodes to connect to cluster [OK]
Common Mistakes:
  • Assuming single node is enough for cluster
  • Confusing default Redis port with cluster ports
  • Misconfiguring cluster option
5. You want to optimize your Redis cluster client to handle failover smoothly. Which approach best uses client-side cluster support to achieve this?
hard
A. Connect only to the master node and manually switch to replicas on failure.
B. Configure the client with multiple cluster nodes and enable automatic node discovery and retries.
C. Disable cluster mode and connect to nodes one by one in round-robin fashion.
D. Use a single client connection and restart it on any error.

Solution

  1. Step 1: Understand failover handling in cluster clients

    Good cluster clients support automatic discovery of nodes and retry commands on failover.
  2. Step 2: Evaluate options for smooth failover

    Configure the client with multiple cluster nodes and enable automatic node discovery and retries. uses multiple nodes and automatic discovery, which helps the client adapt to cluster changes without manual intervention.
  3. Final Answer:

    Configure the client with multiple cluster nodes and enable automatic node discovery and retries. -> Option B
  4. Quick Check:

    Automatic discovery and retries = smooth failover [OK]
Hint: Use multiple nodes and enable auto discovery for failover [OK]
Common Mistakes:
  • Relying on manual failover switching
  • Disabling cluster mode loses benefits
  • Restarting client on every error is inefficient
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