@@ -106,7 +106,7 @@ function _M.connect(self, params)
106
106
107
107
if params .sentinels then
108
108
setmetatable (params , { __index = DEFAULTS } )
109
- return self :connect_via_sentinel (params . sentinels , params . master_name , params . role )
109
+ return self :connect_via_sentinel (params )
110
110
elseif params .startup_cluster_nodes then
111
111
setmetatable (params , { __index = DEFAULTS } )
112
112
-- TODO: Implement cluster
@@ -127,7 +127,13 @@ local function sort_by_localhost(a, b)
127
127
end
128
128
129
129
130
- function _M .connect_via_sentinel (self , sentinels , master_name , role )
130
+ function _M .connect_via_sentinel (self , params )
131
+ local sentinels = params .sentinels
132
+ local master_name = params .master_name
133
+ local role = params .role
134
+ local db = params .db
135
+ local password = params .password
136
+
131
137
local sentnl , err , previous_errors = self :try_hosts (sentinels )
132
138
if not sentnl then
133
139
return nil , err , previous_errors
@@ -136,6 +142,9 @@ function _M.connect_via_sentinel(self, sentinels, master_name, role)
136
142
if role == " master" or role == " any" then
137
143
local master , err = sentinel .get_master (sentnl , master_name )
138
144
if master then
145
+ master .db = db
146
+ master .password = password
147
+
139
148
local redis , err = self :connect_to_host (master )
140
149
if redis then
141
150
sentnl :set_keepalive ()
@@ -159,6 +168,13 @@ function _M.connect_via_sentinel(self, sentinels, master_name, role)
159
168
-- Put any slaves on 127.0.0.1 at the front
160
169
tbl_sort (slaves , sort_by_localhost )
161
170
171
+ if db or password then
172
+ for i ,slave in ipairs (slaves ) do
173
+ slave .db = db
174
+ slave .password = password
175
+ end
176
+ end
177
+
162
178
local slave , err , previous_errors = self :try_hosts (slaves )
163
179
if not slave then
164
180
return nil , err , previous_errors
0 commit comments