Skip to content

Commit 6a73aa5

Browse files
committed
fix: unix domain sockets were not configurable
1 parent d7c8be3 commit 6a73aa5

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

lib/resty/redis/connector.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ end
2323
local fixed_field_metatable = {
2424
__index =
2525
function(t, k)
26-
error("field " .. tostring(k) .. " does not exist", 2)
26+
error("field " .. tostring(k) .. " does not exist", 3)
2727
end,
2828
__newindex =
2929
function(t, k, v)
30-
error("attempt to create new field " .. tostring(k), 2)
30+
error("attempt to create new field " .. tostring(k), 3)
3131
end,
3232
}
3333

@@ -122,7 +122,7 @@ function _M.new(config)
122122
return nil, config -- err
123123
else
124124
return setmetatable({
125-
config = config
125+
config = setmetatable(config, fixed_field_metatable)
126126
}, mt)
127127
end
128128
end
@@ -283,13 +283,13 @@ function _M.connect_to_host(self, host)
283283
r:set_timeout(config.connect_timeout)
284284

285285
local ok, err
286-
local socket = host.socket
286+
local path = host.path
287287
local opts = config.connection_options
288-
if socket then
288+
if path and path ~= "" then
289289
if opts then
290-
ok, err = r:connect(socket, config.connection_options)
290+
ok, err = r:connect(path, config.connection_options)
291291
else
292-
ok, err = r:connect(socket)
292+
ok, err = r:connect(path)
293293
end
294294
else
295295
if opts then

t/connector.t

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ location /t {
2828
port = $TEST_NGINX_REDIS_PORT
2929
})
3030

31-
local redis = assert(rc:connect(params),
31+
local redis, err = assert(rc:connect(params),
3232
"connect should return positively")
3333

3434
assert(redis:set("dog", "an animal"),
@@ -211,3 +211,23 @@ location /t {
211211
GET /t
212212
--- error_log
213213
ERR Client sent AUTH, but no password is set
214+
215+
216+
=== TEST 7: unix domain socket
217+
--- http_config eval: $::HttpConfig
218+
--- config
219+
location /t {
220+
lua_socket_log_errors Off;
221+
content_by_lua_block {
222+
local redis, err = require("resty.redis.connector").new({
223+
path = "unix://tmp/redis.sock",
224+
}):connect()
225+
226+
assert(not redis and err == "no such file or directory",
227+
"bad domain socket should fail")
228+
}
229+
}
230+
--- request
231+
GET /t
232+
--- no_error_log
233+
[error]

0 commit comments

Comments
 (0)