将初始化修改为使用管道进行存储到redis中
This commit is contained in:
parent
a662650dc7
commit
e95d2a0ee5
11
src/init.lua
11
src/init.lua
|
|
@ -53,6 +53,8 @@ local function handler()
|
||||||
--获取数据表中的记录数
|
--获取数据表中的记录数
|
||||||
local code, res = roleDao:getAllSystemRoles()
|
local code, res = roleDao:getAllSystemRoles()
|
||||||
if res == nil then return end
|
if res == nil then return end
|
||||||
|
--管道进行redis处理
|
||||||
|
red:init_pipeline()
|
||||||
--读取角色id和角色名称
|
--读取角色id和角色名称
|
||||||
for _, row in pairs(res) do
|
for _, row in pairs(res) do
|
||||||
local id = row.id --:1
|
local id = row.id --:1
|
||||||
|
|
@ -65,12 +67,13 @@ local function handler()
|
||||||
local perm = ret.permission_code
|
local perm = ret.permission_code
|
||||||
local key = name.."-"..perm
|
local key = name.."-"..perm
|
||||||
--role_name-permission_code 组成key进行验证 存储到redis中
|
--role_name-permission_code 组成key进行验证 存储到redis中
|
||||||
local ok, err = red:set(key, "1")
|
red:set(key, "1")
|
||||||
if not ok then
|
|
||||||
ngx.log(ngx.ERR, "redis failed to set key: "..err)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local results, err = red:commit_pipeline()
|
||||||
|
if not results then
|
||||||
|
ngx.log(ngx.ERR, "init failed to commit the pipelined requests: ", err)
|
||||||
|
end
|
||||||
--关闭redis连接
|
--关闭redis连接
|
||||||
red:close()
|
red:close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,13 @@ function _M:getRolePermissions(role_name)
|
||||||
return allPermissions
|
return allPermissions
|
||||||
end
|
end
|
||||||
--获取redis中所有匹配的数据内容
|
--获取redis中所有匹配的数据内容
|
||||||
local prefix = role_name.."-"
|
local pattern = role_name.."-*"
|
||||||
local cursor = "0"
|
local cursor = "0"
|
||||||
local result = red:call('SCAN', cursor, 'MATCH', prefix .. '*', 'COUNT')
|
local result, err = red:scan(cursor, 'MATCH', pattern)
|
||||||
if result == false then
|
if not result then
|
||||||
return allPermissions
|
return allPermissions
|
||||||
end
|
end
|
||||||
--cursor = result[1]
|
cursor = result[1]
|
||||||
for _, key in ipairs(result[2]) do
|
for _, key in ipairs(result[2]) do
|
||||||
table.insert(allPermissions, key)
|
table.insert(allPermissions, key)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user