lua_shared_dict 和resty.lock的使用

nginx.conf 配置:

lua_shared_dict test 100k;

代码样例
local lock, err = resty_lock:new("test") --create_lock
if not lock then
    return log_error("failed to create lock: ", err)
end

local elapsed, err = lock:lock('my_lock_handler') --acquire_lock
if not elapsed then
    return log_error("failed to acquire the lock: ", err)
end

。。。
对dict里的内容进行操作

local ok, err = lock:unlock() --release_lock
if not ok then
    return log_error("failed to unlock: ", err)
end


版权声明:本文为jgywoshiyy原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。