init_worker_by_lua_block { local slock = require("slock") slock:connect("lock1", "127.0.0.1", 5658) }
server { listen 80;
location /flow/tokenbucket { access_by_lua_block { local slock = require("slock") local client = slock:get("lock1") local flow_key = ngx.var.flow_key or "flow:tokenbucket" local lock = client:newTokenBucketFlow(flow_key, 10, 5, 60) local ok, err = lock:acquire() if not ok then ngx.say("acquire error:" .. err) ngx.exit(ngx.HTTP_OK) end }