获取角色和权限数据表中的数据将其组成键值存储到redis中

This commit is contained in:
wanglei 2025-11-08 10:09:25 +08:00
parent 0308965255
commit bf034e94c8

View File

@ -7,9 +7,11 @@
"ngx_lua""init_by_lua_file";
nginx时初始化一次
--]]
require("config")
--只在第一个worker进程中执行一次
if ngx.worker.id() ~= 0 then
return
end
print("init application...")
--判断程序是否加载权限数据
--local dict = ngx.shared.dict
--local load = dict:get("RBAC")
@ -17,10 +19,8 @@ print("init application...")
-- return
--end
--只在第一个worker进程中执行一次
if ngx.worker.id() ~= 0 then
return
end
require("config")
print("init application woker id:", ngx.worker.id())
--初始化获取系统默认的用户权限为实现RBAC框架做权限数据准备
local function handler()
@ -60,10 +60,11 @@ local function handler()
--row.status:0,
local code, rest = roleDao:getPermission2roleId(id)
for _, ret in pairs(rest) do
--将数据存储到redis中
--获取数据表中的数据
local permid = ret.permission_id
local perm = ret.permission_code
local key = name.."-"..perm
--role_name-permission_code 组成key进行验证 存储到redis中
local ok, err = red:set(key, "1")
if not ok then
ngx.log(ngx.ERR, "redis failed to set key: "..err)
@ -73,6 +74,7 @@ local function handler()
--关闭redis连接
red:close()
--共享数据字典进行数据存储
--dict:set("RBAC", "1")
end