Quick revision
The short answer
Single-key commands, @Cacheable caches and most RedisTemplate operations keep working, because the client routes each key to the node that owns its slot. Three things change: a cluster has only database 0, so data separated by spring.data.redis.database must move to key prefixes; multi-key commands, MULTI/EXEC and Lua scripts only work when their keys share a slot, and Spring Data Redis does not support transactions on cluster connections; and KEYS and SCAN become per-node operations that Spring fans out to every primary. Classic pub/sub keeps working but broadcasts every message to every node, while sharded pub/sub in Redis 7 scales better.
What to remember
In this answer, we saw that Redis Cluster spreads keys across nodes by hash slot, so single-key operations, @Cacheable and most RedisTemplate calls work unchanged. Databases other than 0 disappear and must become key prefixes, multi-key operations are split and no longer atomic, KEYS and SCAN become cluster-wide fan-outs, and MULTI/EXEC through Spring Data Redis and Lua scripts across slots stop working unless keys share a hash tag. Classic pub/sub still works but broadcasts to every node, and sharded pub/sub is the scalable option where clients support it.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Single-key commands, @Cacheable caches and most RedisTemplate operations keep working, because the client routes each key to the node that owns its slot. Three things change: a cluster has only database 0, so data separated by spring.data.redis.database must move to key prefixes; multi-key commands, MULTI/EXEC and Lua scripts only work when their keys share a slot, and Spring Data Redis does not support transactions on cluster connections; and KEYS and SCAN become per-node operations that Spring fans out to every primary. Classic pub/sub keeps working but broadcasts every message to every node, while sharded pub/sub in Redis 7 scales better.
Why this question is asked
Moving to Redis Cluster looks like a one-line configuration change, and for most of the code it is. The trouble comes from the parts of a service that assumed one server held every key. Interviewers ask this to see whether we can predict which features survive and which break before we find out in production. In this answer, we will recap how a cluster spreads keys, go through what keeps working, what behaves differently, and what stops working, and see how the message listener fits in.
1A Quick Recap of How a Cluster Spreads Keys
Redis Cluster divides the keyspace into 16,384 hash slots and gives each primary a range of them. The slot of a key is CRC16 of the key modulo 16,384. A cluster-aware client such as Lettuce keeps a map from slots to nodes and sends each command to the node that owns the key.
One rule follows from this, and it explains almost everything in this answer: a single command, transaction or script can only touch keys that live on the same node, and Redis enforces the stricter rule that they live in the same slot. Hash tags help here. If a key contains a part in braces, such as cart:{user42}:items, only the part inside the braces is hashed, so keys with the same tag land in the same slot.
2What Keeps Working Unchanged
Anything that works on one key at a time works as before: get, set, increments, hash, list and set operations, expirations. RedisTemplate and the opsForValue, opsForHash and similar operations route each call to the right node. @Cacheable with RedisCacheManager stores each cache entry under one key, so caching keeps working. Spring Session also works, since a session's data is kept under keys for that session.
The client takes care of routing, and when slots move it follows MOVED and ASK redirects. As long as topology refresh is enabled in Lettuce, the service does not notice resharding.
3What Behaves Differently
A cluster has only database 0. Services that separated their data with spring.data.redis.database set to 1 or 2 on the single instance cannot do that any more; SELECT is not allowed in cluster mode. They must use key prefixes instead, such as orders: and reports:, and if two services used the same key names in different databases, those collide in the cluster unless prefixed first.
Multi-key commands change behaviour. MGET or DEL with keys in different slots fail on the server with a CROSSSLOT error, but Spring Data Redis and Lettuce split some of them into per-slot commands and combine the results, so the call succeeds but is no longer atomic and makes several round trips. KEYS and SCAN only see the keys of the node they run on. Spring Data Redis's cluster connection fans calls such as keys() out to every primary and merges the results, which is slow and puts load on the whole cluster, so they must stay out of request paths. This matters for RedisCacheManager too: clearing a cache uses a key pattern by default and becomes a cluster-wide operation.
4What Stops Working
Transactions are the clearest break. Spring Data Redis does not support MULTI/EXEC on cluster connections; calling multi() on a cluster connection throws an exception, so SessionCallback blocks that run MULTI/EXEC need redesign, for example into a Lua script on keys that share a hash tag. Lua scripts themselves keep working only if every key they touch is passed in KEYS and hashes to one slot; a script that builds key names inside itself, or receives keys from different slots, fails with CROSSSLOT or, worse, touches keys on the wrong node.
| Feature | On Redis Cluster |
|---|---|
Single-key commands, RedisTemplate ops | unchanged; client routes by slot |
@Cacheable / RedisCacheManager | works; cache clear becomes cluster-wide |
spring.data.redis.database other than 0 | not available; use key prefixes |
| MGET / DEL across slots | split by client, no longer atomic |
| KEYS / SCAN | per node; fanned out to every primary |
| MULTI/EXEC in Spring Data Redis | not supported on cluster connections |
| Lua scripts | only with all keys in one slot |
| Classic pub/sub | works; every message goes to every node |
5Pub/Sub and the Message Listener
Classic pub/sub keeps working: a RedisMessageListenerContainer subscribes through one node, and a message published on any node reaches it. The reason it works is also its cost. In a cluster, every published message is broadcast across the cluster bus to every node, so pub/sub traffic does not scale with more nodes; it is multiplied by them.
Redis 7 added sharded pub/sub with SSUBSCRIBE and SPUBLISH. A channel is assigned to a slot like a key, and its messages stay on the node that owns that slot and its replicas. That scales with the cluster. Client support varies: Lettuce supports it in recent versions, while Spring Data Redis's listener container may not expose it yet, so check your versions before planning around it.
6Follow-up questions
How would you find KEYS calls hidden inside libraries?
Look at the server rather than the code. INFO commandstats on the current single instance shows cmdstat_keys with a call count, and the slow log usually catches KEYS calls because they are slow on a large keyspace. Running MONITOR briefly in a test environment while exercising the service, or using CLIENT LIST with the lib-name field and SLOWLOG entries that include the client name, points to the caller. Common hidden sources are cache clears with allEntries in Spring Cache, old Spring Session cleanup code and admin endpoints. On Redis 7, ACL rules can deny KEYS in a test environment so any use fails loudly.
Can I keep a transaction across several keys on a cluster?
Only if all the keys share a slot, typically by giving them the same hash tag, and then usually as a Lua script or function rather than MULTI/EXEC through Spring Data Redis. If the keys naturally belong to different entities, the design needs to change, for example to make the operation idempotent and ordered rather than atomic.
Do I need to change my serializers or cache configuration?
No. Serialization is a client concern and is unaffected by clustering. Cache configuration only changes if the cache clear strategy uses KEYS, where a SCAN-based batch strategy or versioned key prefixes are better.
7Conclusion
In this answer, we saw that Redis Cluster spreads keys across nodes by hash slot, so single-key operations, @Cacheable and most RedisTemplate calls work unchanged. Databases other than 0 disappear and must become key prefixes, multi-key operations are split and no longer atomic, KEYS and SCAN become cluster-wide fan-outs, and MULTI/EXEC through Spring Data Redis and Lua scripts across slots stop working unless keys share a hash tag. Classic pub/sub still works but broadcasts to every node, and sharded pub/sub is the scalable option where clients support it.
Open with
Everything that works on one key keeps working: gets, sets, hashes, lists, expirations, most RedisTemplate operations and @Cacheable with RedisCacheManager, because the client routes each key to the node that owns its slot and follows redirects.
Then, if they want more
Some things behave differently. A cluster has only database 0, so a service that used spring.data.redis.database to separate data must switch to key prefixes. Multi-key commands like MGET or DEL across slots fail on the server with CROSSSLOT, but the client splits some of them per slot, so they work but are no longer atomic.
KEYS and SCAN only see one node, and Spring Data Redis fans them out to every primary, which is slow and loads the whole cluster, so they must stay out of request paths, and that includes cache clears that use key patterns. Some things stop working.
MULTI/EXEC is not supported on Spring Data Redis cluster connections, and Lua scripts must receive keys that all hash to one slot, so I would use hash tags like braces around the user id to keep related keys together.
Classic pub/sub with the message listener still works, but every message is broadcast to every node; sharded pub/sub in Redis 7 with SSUBSCRIBE scales better where the client supports it.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Redis 7
- 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 "Which features keep working unchanged, which behave differently, and which stop working...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/66bbbf5885/