Handle -READONLY as a redirection signal for Redis Cluster (AWS ElastiCache support)#1656
Conversation
|
@NivekNK I still don't understand why do we need this specific post-retry exception handling. Since, READONLY error is wrapped into Please provide a unit test case that shows the behaviour if READONLY error wrapped into |
|
@vladvildanov Hi! I've added the unit test you requested to demonstrate the exact behavior when a READONLY error is wrapped inside a As the new test shows, when This is exactly why my explicit handling in Let me know what you think and if you need any further adjustments. I see the CI failed on |
|
@NivekNK Thanks for the detailed explanation, no more objections from my side! |
This PR introduces explicit handling for the
-READONLYerror response within theRedisClusterconnection class.The Problem:
In AWS ElastiCache (Redis OSS mode), when using the Configuration Endpoint (DNS round-robin), a client might occasionally connect to a replica. If a Lua script (with
KEYS[]) is executed against this replica, the server returns a-READONLY You can't write against a read only replicaerror instead of a-MOVEDredirection.Currently, Predis treats this as a generic
ServerException. This can lead to intermittent failures because the internal slot map isn't explicitly marked as stale or updated upon receiving this specific protocol error, causing the retry to potentially hit the same node.The Solution:
onErrorResponseto intercept theREADONLYprefix.onReadOnlyResponsewhich:askSlotMap()to refresh the cluster topology.This approach follows the existing reactive discovery pattern in Predis and ensures high availability in AWS ElastiCache environments without requiring a new configuration option.