Skip to content

Commit 4161175

Browse files
committed
Add auth timeout
1 parent 359e447 commit 4161175

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/redis_client.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,15 +867,30 @@ def connect
867867
def build_prelude_timeouts(prelude, auth_timeout)
868868
return nil unless auth_timeout
869869

870-
timeouts = Array.new(prelude.size)
871-
prelude.each_with_index do |command, index|
872-
next if !command || command.empty?
873-
name = command.first
874-
if name == "AUTH" || (name == "HELLO" && command.include?("AUTH"))
875-
timeouts[index] = auth_timeout
870+
auth_seen = false
871+
timeouts = prelude.map do |command|
872+
if auth_command?(command)
873+
auth_seen = true
874+
auth_timeout
875+
else
876+
nil
876877
end
877878
end
878-
timeouts
879+
880+
auth_seen ? timeouts : nil
881+
end
882+
883+
def auth_command?(command)
884+
return false unless command&.any?
885+
886+
case command.first
887+
when "AUTH"
888+
true
889+
when "HELLO"
890+
command.size >= 3 && command[2] == "AUTH"
891+
else
892+
false
893+
end
879894
end
880895
end
881896

0 commit comments

Comments
 (0)