@@ -9,7 +9,7 @@ local tbl_remove = table.remove
99local tbl_sort = table.sort
1010local ok , tbl_new = pcall (require , " table.new" )
1111if not ok then
12- tbl_new = function (narr , nrec ) return {} end
12+ tbl_new = function (narr , nrec ) return {} end -- luacheck: ignore 212
1313end
1414
1515local redis = require (" resty.redis" )
@@ -22,11 +22,11 @@ local get_slaves = require("resty.redis.sentinel").get_slaves
2222-- A metatable which prevents undefined fields from being created / accessed
2323local fixed_field_metatable = {
2424 __index =
25- function (t , k )
25+ function (t , k ) -- luacheck: ignore 212
2626 error (" field " .. tostring (k ) .. " does not exist" , 3 )
2727 end ,
2828 __newindex =
29- function (t , k , v )
29+ function (t , k , v ) -- luacheck: ignore 212
3030 error (" attempt to create new field " .. tostring (k ), 3 )
3131 end ,
3232}
@@ -66,7 +66,6 @@ local function tbl_copy_merge_defaults(t1, defaults)
6666 if t1 == nil then t1 = {} end
6767 if defaults == nil then defaults = {} end
6868 if type (t1 ) == " table" and type (defaults ) == " table" then
69- local mt = getmetatable (defaults )
7069 local copy = {}
7170 for t1_key , t1_value in next , t1 , nil do
7271 copy [tbl_copy (t1_key )] = tbl_copy_merge_defaults (
@@ -164,6 +163,8 @@ local function parse_dsn(params)
164163
165164 return tbl_copy_merge_defaults (params , parsed_params )
166165 end
166+
167+ return params
167168end
168169_M .parse_dsn = parse_dsn
169170
@@ -173,7 +174,7 @@ function _M.new(config)
173174 if config and config .url then
174175 local err
175176 config , err = parse_dsn (config )
176- if not config then ngx_log (ngx_ERR , err ) end
177+ if err then ngx_log (ngx_ERR , err ) end
177178 end
178179
179180 local ok , config = pcall (tbl_copy_merge_defaults , config , DEFAULTS )
@@ -198,7 +199,7 @@ function _M.connect(self, params)
198199 if params and params .url then
199200 local err
200201 params , err = parse_dsn (params )
201- if not params then ngx_log (ngx_ERR , err ) end
202+ if err then ngx_log (ngx_ERR , err ) end
202203 end
203204
204205 params = tbl_copy_merge_defaults (params , self .config )
@@ -234,18 +235,20 @@ function _M.connect_via_sentinel(self, params)
234235
235236 if role == " master" then
236237 local master , err = get_master (sentnl , master_name )
237- if master then
238- master .db = db
239- master .password = password
240-
241- local redis , err = self :connect_to_host (master )
242- if redis then
243- sentnl :set_keepalive ()
244- return redis , err
245- else
246- if role == " master" then
247- return nil , err
248- end
238+ if not master then
239+ return nil , err
240+ end
241+
242+ master .db = db
243+ master .password = password
244+
245+ local redis , err = self :connect_to_host (master )
246+ if redis then
247+ sentnl :set_keepalive ()
248+ return redis , err
249+ else
250+ if role == " master" then
251+ return nil , err
249252 end
250253 end
251254
@@ -262,7 +265,7 @@ function _M.connect_via_sentinel(self, params)
262265 tbl_sort (slaves , sort_by_localhost )
263266
264267 if db or password then
265- for i , slave in ipairs (slaves ) do
268+ for _ , slave in ipairs (slaves ) do
266269 slave .db = db
267270 slave .password = password
268271 end
@@ -304,7 +307,7 @@ function _M.connect_to_host(self, host)
304307 -- Stub out methods for disabled commands
305308 if next (config .disabled_commands ) then
306309 for _ , cmd in ipairs (config .disabled_commands ) do
307- r [cmd ] = function (... )
310+ r [cmd ] = function ()
308311 return nil , (" Command " .. cmd .. " is disabled" )
309312 end
310313 end
0 commit comments