Skip to content

fix bug at @get_connection_by_slot: fix node[2] nil error (this the p… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions resty/redis_cluster.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
local redis = require "resty.redis"
local bit = require "bit"

--字符串分割函数
--传入字符串和分隔符,返回分割后的table
function Split(str, delimiter)
if str==nil or str=='' or delimiter==nil then
return nil
end

local result = {}
for match in (str..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end

local setmetatable = setmetatable
local pairs = pairs
local sub = string.sub
Expand Down Expand Up @@ -321,6 +335,12 @@ function _M.get_connection_by_slot(self, slot)
return self:get_random_connection()
end

if node[2] == nil then
local addr = Split(node[3], ':')
local ports = Split(addr[2], '@')
node[2] = ports[1]
end

return get_redis_link(node[1], node[2], cluster.timeout)
end
--执行命令
Expand Down