Skip to content

Commit 598dc4d

Browse files
committed
Ensure parsed db and port are treated as numbers
1 parent be6b7d1 commit 598dc4d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/resty/redis/connector.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ local function parse_dsn(params)
157157
local parsed_params = {}
158158

159159
for i,v in ipairs(fields) do
160-
parsed_params[v] = m[i + 1]
160+
if v == "db" or v == "port" then
161+
parsed_params[v] = tonumber(m[i + 1])
162+
else
163+
parsed_params[v] = m[i + 1]
164+
end
165+
161166
if v == "role" then
162167
parsed_params[v] = roles[parsed_params[v]]
163168
end
@@ -362,6 +367,7 @@ function _M.connect_to_host(self, host)
362367
-- No support for DBs in proxied Redis.
363368
if config.connection_is_proxied ~= true and host.db ~= nil then
364369
local res, err = r:select(host.db)
370+
365371
-- SELECT will fail if we are connected to sentinel:
366372
-- detect it and ignore error message it that's the case
367373
if err and str_find(err, "ERR unknown command") then

0 commit comments

Comments
 (0)