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