RedisClient::ConnectionError with pubsub
Closed this issue · 5 comments
Hello,
I just switched from redis-rb
to redis-client
and I see some connection errors on one of my production instance.
I use the code :
$conn = RedisClient.new(reconnect_attempts: 1).pubsub
and $conn.call('publish', event, payload.to_json)
.
After some time I see some RedisClient::ConnectionError
Not connected
or Broken pipe
errors raised by
/app/shared/bundle/ruby/3.0.0/gems/hiredis-client-0.14.1/lib/redis_client/hiredis_connection.rb:94:in `_write'
/app/shared/bundle/ruby/3.0.0/gems/hiredis-client-0.14.1/lib/redis_client/hiredis_connection.rb:94:in `write'
/app/shared/bundle/ruby/3.0.0/gems/redis-client-0.14.1/lib/redis_client.rb:421:in `call'
/app/releases/20230522090020/lib/pubsub_singleton.rb:69:in `publish'
Is the reconnect_attempts
also used after a broken connection ? Am I missing a parameter that used to make redis-rb work and not redis-client?
Thanks for your help and for the good work!
See: https://github.com/redis-rb/redis-client#reconnection
redis-rb
does retry by default, and that's probably what was hiding these events to you. You can pass reconnect_attempts: 1
to restore the old behavior.
Duplicate of #116
I saw this issue and I modified my code already (as you can see in my first post) but it didn't solve my problem.
The errors are raised after few minutes/hours of connection, not when the connection is created. So I'm not sure it's the same thing than #116
Apologies, I read a bit too fast, didn't notice it was about pubsub specifically.
So, I will leave this open as a reminder to improve the Readme.
But the answer is that reconnect_attempts
doesn't apply to pubsub
connections because these are stateful, so reconnecting automatically would require to keep track of which channel you subscribed to, and to re-subscribe to them all.
So redis-client
expect the caller to implement this logic themselves.
That makes sense!
Thanks for your help.