Skip to content

Commit 71cab75

Browse files
committed
style(*) local vars and functions
1 parent 5431327 commit 71cab75

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/resty/redis/connector.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
local redis = require "resty.redis"
2-
redis.add_commands("sentinel")
3-
local sentinel = require "resty.redis.sentinel"
4-
1+
local ipairs, pcall, error, tostring, type, next, setmetatable, getmetatable =
2+
ipairs, pcall, error, tostring, type, next, setmetatable, getmetatable
53

6-
local ipairs, setmetatable, pcall = ipairs, setmetatable, pcall
74
local ngx_log = ngx.log
85
local ngx_ERR = ngx.ERR
96
local ngx_re_match = ngx.re.match
7+
108
local tbl_remove = table.remove
119
local tbl_sort = table.sort
12-
1310
local ok, tbl_new = pcall(require, "table.new")
1411
if not ok then
1512
tbl_new = function (narr, nrec) return {} end
1613
end
1714

15+
local redis = require("resty.redis")
16+
redis.add_commands("sentinel")
17+
18+
local get_master = require("resty.redis.sentinel").get_master
19+
local get_slaves = require("resty.redis.sentinel").get_slaves
20+
1821

1922
-- A metatable which prevents undefined fields from being created / accessed
2023
local fixed_field_metatable = {
@@ -86,15 +89,14 @@ local DEFAULTS = setmetatable({
8689
connect_timeout = 100,
8790
read_timeout = 1000,
8891
connection_options = {}, -- pool, etc
89-
9092
keepalive_timeout = 60000,
9193
keepalive_poolsize = 30,
94+
9295
host = "127.0.0.1",
9396
port = 6379,
9497
path = "", -- /tmp/redis.sock
9598
password = "",
9699
db = 0,
97-
98100
url = "", -- DSN url
99101

100102
master_name = "mymaster",
@@ -196,7 +198,7 @@ function _M.connect_via_sentinel(self, params)
196198
end
197199

198200
if role == "master" or role == "any" then
199-
local master, err = sentinel.get_master(sentnl, master_name)
201+
local master, err = get_master(sentnl, master_name)
200202
if master then
201203
master.db = db
202204
master.password = password
@@ -214,7 +216,7 @@ function _M.connect_via_sentinel(self, params)
214216
end
215217

216218
-- We either wanted a slave, or are failing over to a slave "any"
217-
local slaves, err = sentinel.get_slaves(sentnl, master_name)
219+
local slaves, err = get_slaves(sentnl, master_name)
218220
sentnl:set_keepalive()
219221

220222
if not slaves then

lib/resty/redis/sentinel.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
local ipairs, type = ipairs, type
2+
23
local ngx_null = ngx.null
3-
local tbl_insert = table.insert
44

5+
local tbl_insert = table.insert
56
local ok, tbl_new = pcall(require, "table.new")
67
if not ok then
78
tbl_new = function (narr, nrec) return {} end
89
end
910

1011

11-
local _M = {}
12-
_M._VERSION = 0.03
12+
local _M = {
13+
_VERSION = '0.03'
14+
}
1315

1416

1517
function _M.get_master(sentinel, master_name)

0 commit comments

Comments
 (0)