From 2106ae2c8d5986d0784cd237d1724bf17502f766 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 7 Dec 2023 11:41:04 +0100 Subject: [PATCH] Revalidate connection in `RedisClient#connected?` Otherwise if it has pending reads it will be closed when used anyway. --- CHANGELOG.md | 1 + lib/redis_client.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b09975..97cb65b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- Revalidate connection in `RedisClient#connected?` - Eagerly fail if `db:` isn't an Integer. #151. # 0.18.0 diff --git a/lib/redis_client.rb b/lib/redis_client.rb index a323a55..52ad446 100644 --- a/lib/redis_client.rb +++ b/lib/redis_client.rb @@ -222,17 +222,18 @@ def with(_options = nil) def timeout=(timeout) super - raw_connection.read_timeout = raw_connection.write_timeout = timeout if connected? + @raw_connection&.read_timeout = timeout + @raw_connection&.write_timeout = timeout end def read_timeout=(timeout) super - raw_connection.read_timeout = timeout if connected? + @raw_connection&.read_timeout = timeout end def write_timeout=(timeout) super - raw_connection.write_timeout = timeout if connected? + @raw_connection&.write_timeout = timeout end def pubsub @@ -386,7 +387,7 @@ def zscan(key, *args, **kwargs, &block) end def connected? - @raw_connection&.connected? + @raw_connection&.revalidate end def close