redis-rb / redis-client

Simple low level client for Redis 6+
MIT License
124 stars 60 forks source link

Attempt Reconnect on Redis::CommandError (Elasticache failover) #69

Closed tylerbrewer2 closed 1 year ago

tylerbrewer2 commented 1 year ago

Hello!

I'm digging into some process crashes after an Elasticache failover. It appears as if a READONLY You can't write against a read only replica. (Redis::CommandError) error is returned after the failover. I believe this is because redis-client is still connected to the old primary node instead of the new primary node.

Is there a way to reset connection after a command error? Looking here, it looks like only ConnectionError and ProtocolError is handled, which I'm sure is for a very good reason.

Apologies if my assumptions are wrong here and I'm misreading the code. Thanks for the library!

byroot commented 1 year ago

As of https://github.com/redis-rb/redis-client/pull/65 (released as 0.11.2), READONLY are treated as ConnectionError.

So this is handled now.

I still need to update the error in redis-rb though: https://github.com/redis/redis-rb/blob/fe90f6d2dc4fd822cc45fb3809529334bae420fa/lib/redis/errors.rb#L29

tylerbrewer2 commented 1 year ago

Awesome, thank you!

I went ahead and opened a PR. I believe most of the logic related to this change lives in redis-client (I could be, and likely am, wrong).