Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- location /test {
-- content_by_lua_block {
local redis_client = redis_cluster:new(config)
--- simulating a dynamic code being stored at Redis ---
redis_client:set('authentication', "access_by_lua_block||local token = ngx.var.arg_token or ngx.var.cookie_superstition \n if token ~= 'token' then \n return ngx.exit(ngx.HTTP_FORBIDDEN) \n else \n ngx.header['Set-Cookie'] = {'superstition=token'} \n end")
redis_client:sadd('coding_units', 'authentication')
--- simulating a dynamic code being stored at Redis ---
--- fetch ---
local resp, err = redis_client:smembers("coding_units")
local raw_coding_units = {}
for _, coding_unit_key in ipairs(resp) do
local resp, err = redis_client:get(coding_unit_key)
table.insert(raw_coding_units, resp)
end
--- fetch ---
--- parse ---
local coding_units = {}
for _, raw_coding_unit in ipairs(raw_coding_units) do
local parts = mysplit(raw_coding_unit, "||")
local cu = {}
cu['phase'] = parts[1]
cu['code'] = parts[2]
table.insert(coding_units, cu)
end
--- parse ---
--- execute ---
for _, coding_unit in ipairs(coding_units) do
ngx.log(ngx.ERR, "phase ", coding_unit['phase'])
ngx.log(ngx.ERR, "code ", coding_unit['code'])
local function_code, err = loadstring(coding_unit['code'])
ngx.log(ngx.ERR, "loadstring error ", err)
local status, ret = xpcall(function_code, err_handler)
ngx.log(ngx.ERR, "xpcall status ", status, " ret ", ret)
end
--- execute ---
ngx.say(" R$ 45,567,900,00 ") -- a random value
-- }
-- }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.