One approach is to emulate a global lock in shdict and only the
request obtaining the lock can proceed and other requests have to wait
on the lock. The access_by_lua directive is your friend here and you
can put the lock-fetching and lock-waiting logic there. The logic for
releasing the lock should go to the log_by_lua.
How would you implement lock waiting?
Infinite loop polling for lock?
Or, am I better off using redis?
access_by_lua = '
local Redis = require('resty.redis')
local redis = Redis:new()
local ok, err, res
ok, err = redis:connect('127.0.0.1', 6379)
res, err = redis:subscribe('Chan')
res, err = redis:read_reply() -- waits indefinitely for message.
'
And, Redis:new() and redis:connect() should go to init_by_lua ?