Scrivio Interview library
ConceptFoundations6 min read · updated 13 November 2026

A service using Lettuce's cluster client calls MGET with 200 keys and DEL with 50 keys spread over many slots. Both work, although the Redis documentation says multi-key commands need all keys in one slot.

Why do these calls work, what is the client doing behind the scenes, and which guarantees are lost compared with a single Redis instance?

The server never sees a cross-slot command: Lettuce's cluster client splits MGET, MSET, DEL, UNLINK, EXISTS and TOUCH by slot, sends one command per slot to the owning nodes in parallel and merges the results in key order. What we lose is atomicity, since other clients can see some keys changed and others not and a node failure can leave a partial result, and much of the batching benefit, since 200 random keys become dozens of commands. Commands that cannot be split, such as transactions, multi-key Lua scripts or SUNIONSTORE across slots, still fail with CROSSSLOT.

Why this question is asked

This question catches people who learned that Redis Cluster rejects multi-key commands across slots, then see their code doing exactly that without errors. The answer is that the client library quietly does the splitting, and the convenience hides a change in guarantees. Interviewers ask it to see whether we know where the work happens, what it costs, and which guarantees a single Redis instance gave us that we no longer have. In this answer, we will recap the server's rule, look at what Lettuce does behind the scenes, count the cost, list what is lost and what still fails, and see how Spring Data Redis behaves.

1A Quick Recap of the Server's Rule

In Redis Cluster each key belongs to one of 16,384 slots, and each slot lives on one primary. A Redis node can only execute a command over keys it owns, so the server requires all keys of a multi-key command to be in the same slot. If they are not, it answers with the CROSSSLOT error, even if both slots happen to live on the same node.

On a single Redis instance, MGET of 200 keys is one command, executed atomically: no other client's command runs in between, so the result is a consistent snapshot.

2What Lettuce Does Behind the Scenes

Lettuce's advanced cluster API, the RedisAdvancedClusterCommands interface, implements several multi-key commands itself. For MGET it computes the slot of every key, groups the keys by slot, sends one MGET per slot to the node that owns it, all in parallel, and puts the results back in the order of the original keys. MSET, DEL, UNLINK, EXISTS and TOUCH are handled the same way, with DEL and EXISTS adding up the counts from each part.

Java
RedisClusterClient client = RedisClusterClient.create("redis://10.0.0.11:6379");
RedisAdvancedClusterCommands<String, String> redis = client.connect().sync();
List<KeyValue<String, String>> values = redis.mget("user:1", "user:2"); // slots 10778 and 6777
// on the wire: MGET user:1 -> node owning 10778, MGET user:2 -> node owning 6777, in parallel
// result: [KeyValue[user:1, alice], KeyValue[user:2, bob]] in the original order
long deleted = redis.del("user:1", "user:2", "user:3"); // 3: sum of per-slot DELs
Step throughOne MGET of keys in two slots
ServiceLettuceNode ANode B
mget(user:1, user:2)
group keys by slot
MGET user:1
MGET user:2
[alice]
[bob]
[alice, bob] in key order

7 messages in order. Play them, or step through them one at a time.

3What It Costs

The number of commands grows with the number of distinct slots, not the number of keys. 200 random keys fall into almost 200 different slots, spread over every primary. Lettuce groups them per slot, so the request becomes many commands sent to all nodes, and the response is ready only when the slowest node has answered. With six primaries, one node's garbage collection pause or busy moment now delays every MGET.

So the benefit of batching shrinks. A single MGET of 200 keys on one instance is one round trip; across a cluster it is a fan-out whose latency follows the slowest node. It is still usually faster than 200 separate GETs, because the commands go out in parallel and are pipelined, but it is not the cheap operation it looks like.

4Which Guarantees Are Lost

Atomicity is gone. Between the per-slot parts, other clients' commands run. An MSET of ten keys can be observed by another client with five new values and five old ones. A DEL of 50 keys can partly succeed: if one node fails or a timeout hits one part, some keys are deleted and others are not, and the call reports an error or a partial count. On a single instance neither can happen.

Commands that cannot be split this way still fail with CROSSSLOT, because splitting them would change their meaning: MULTI/EXEC transactions over keys in several slots, Lua scripts whose KEYS span slots, SUNIONSTORE or SINTERSTORE where the destination and sources are in different slots, and RENAME or SMOVE across slots.

Multi-key commands on a cluster client
CommandAcross slots with LettuceAtomic?
MGET, MSETsplit per slot, mergedno
DEL, UNLINK, EXISTS, TOUCHsplit per slot, counts summedno
MULTI/EXECCROSSSLOT erroronly within one slot
EVAL with keys in several slotsCROSSSLOT erroronly within one slot
SUNIONSTORE, RENAME, SMOVECROSSSLOT erroronly within one slot

5Spring Data Redis on a Cluster

Spring Data Redis also has cluster-aware code. On a cluster connection, some multi-key operations are split by slot and executed on the right nodes, while others are rejected or only work when all keys share a slot. Behaviour differs per operation and has changed between versions, so for every multi-key call we rely on, check the Spring Data Redis reference for cluster support and test it against a real cluster rather than a single instance.

6Follow-up questions

When would you add a hash tag even though the client splits commands for you?

When the keys must change together atomically, for example a cart's items and its metadata, because only keys in one slot can share a transaction or a Lua script. Also when a group of keys is always read together on a hot path: tagging them into one slot turns a fan-out to many nodes into a single command to one node, with lower and more predictable latency. The tag should cover the smallest unit that needs it, never a broad value that would pile data onto one shard.

Does the split MGET return a consistent snapshot?

No. Each per-slot MGET is consistent on its own, but different slots are read at slightly different moments, so the combined result can mix values from before and after another client's update.

What happens to the call if one node is failing over?

The part sent to that node fails or waits for the timeout, while the other parts succeed. Lettuce then reports an error for the whole call, even though some parts were applied, which is why writes through split commands must be safe to retry.

7Conclusion

In this answer, we saw that Redis Cluster rejects cross-slot commands, but Lettuce's cluster API splits MGET, MSET, DEL, UNLINK, EXISTS and TOUCH by slot, runs the parts in parallel on the owning nodes and merges the results in key order. The price is lost atomicity, possible partial results on failures, and a fan-out whose latency follows the slowest node. Transactions, multi-slot Lua scripts and commands like SUNIONSTORE or RENAME across slots still fail with CROSSSLOT, and Spring Data Redis has its own per-operation cluster support to check.

What to say in the interviewAbout 90 seconds aloud

Open with

They work because the server never receives a cross-slot command. Lettuce's advanced cluster API implements several multi-key commands itself, including MGET, MSET, DEL, UNLINK, EXISTS and TOUCH. It calculates the slot of each key, groups the keys by slot, sends one command per slot to the node that owns it, in parallel, and then merges the results back in the original key order, or adds up the counts for DEL and EXISTS.

Then, if they want more

So there is no CROSSSLOT error. What we lose compared with a single Redis is atomicity.

On one instance an MGET or MSET runs as one command with nothing in between; on the cluster, other clients can see some keys changed and others not, and if a node fails or times out, part of a DEL or MSET can be applied while the call reports an error.

The cost also changes: 200 random keys hit almost 200 slots across all primaries, so the call becomes a fan-out and its latency follows the slowest node, which shrinks the benefit of batching.

Commands whose meaning depends on running together cannot be split, so MULTI and EXEC, Lua scripts over several slots, SUNIONSTORE or RENAME across slots still fail with CROSSSLOT. Spring Data Redis on a cluster connection splits some operations and rejects others, so I would check its documentation and test each multi-key call we rely on against a real cluster.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Why do these calls work, what is the client doing behind the scenes, and which...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/875557d4d8/