File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed
Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ local ngx_log = ngx.log
55local ngx_ERR = ngx .ERR
66local ngx_re_match = ngx .re .match
77
8+ local str_find = string.find
89local tbl_remove = table.remove
910local tbl_sort = table.sort
1011local ok , tbl_new = pcall (require , " table.new" )
@@ -356,14 +357,24 @@ function _M.connect_to_host(self, host)
356357 if password and password ~= " " then
357358 local res , err = r :auth (password )
358359 if err then
359- ngx_log (ngx_ERR , err )
360360 return res , err
361361 end
362362 end
363363
364364 -- No support for DBs in proxied Redis.
365365 if config .connection_is_proxied ~= true and host .db ~= nil then
366- r :select (host .db )
366+ local res , err = r :select (host .db )
367+ -- SELECT will fail if we are connected to sentinel:
368+ -- detect it and ignore error message it that's the case
369+ if err and str_find (err , " ERR unknown command" ) then
370+ local role = r :role ()
371+ if role and role [1 ] == " sentinel" then
372+ err = nil
373+ end
374+ end
375+ if err then
376+ return res , err
377+ end
367378 end
368379 return r , nil
369380 end
Original file line number Diff line number Diff line change @@ -210,8 +210,8 @@ location /t {
210210}
211211-- - request
212212GET / t
213- -- - error_log
214- ERR Client sent AUTH, but no password is set
213+ -- - no_error_log
214+ [error]
215215
216216
217217=== TEST 7 : Bad unix domain socket path should fail
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ location /t {
3232 local rc = require("resty.redis.connector").new()
3333
3434 local sentinel, err = rc:connect{ url = "redis://127.0.0.1:$TEST_NGINX_SENTINEL_PORT1" }
35- assert(sentinel and not err, "sentinel should connect without errors" )
35+ assert(sentinel and not err, "sentinel should connect without errors but got " .. tostring(err) )
3636
3737 local master, err = require("resty.redis.sentinel").get_master(
3838 sentinel,
You can’t perform that action at this time.
0 commit comments