Skip to content

Commit af0b66c

Browse files
authored
Merge pull request #990 from redis/fix-older-redis-auth
Fix password authentication on Redis 5 and older
2 parents a5c1cee + 98cc390 commit af0b66c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/redis/client.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,17 @@ def connect
115115
# Don't try to reconnect when the connection is fresh
116116
with_reconnect(false) do
117117
establish_connection
118-
call [:auth, username, password].compact if username || password
118+
if password
119+
if username
120+
begin
121+
call [:auth, username, password]
122+
rescue CommandError # Likely on Redis < 6
123+
call [:auth, password]
124+
end
125+
else
126+
call [:auth, password]
127+
end
128+
end
119129
call [:select, db] if db != 0
120130
call [:client, :setname, @options[:id]] if @options[:id]
121131
@connector.check(self)

0 commit comments

Comments
 (0)