nginx and redis as pastebin
requirement : redis nginx lua snippets nginx access_by_lua_block { local redis = require "resty.redis" local red = redis:new() red:set_timeout(1000) -- 1 sec local ok, err = red:connect("127.0.0.1", 6379,"pool_size=128") if not ok then ngx.exit(503) return end local key = ngx.var.uri local method = ngx.var.request_method if method == "POST" or method == "PUT" then -- local set value = ngx ngx.req.read_body() local data = ngx.req.get_body_data() red:set(key,data) ngx.say("ok") return end if method == "GET" then local res, err = red:get(key) if res ~= ngx.null then -- ngx.redirect(res, 301) ngx.header["Content-type"] = "text/plain; charset=UTF-8" ngx.say(res) return end end if method == "DELETE" then red:del(key) ngx.say("deleted") -- return end } location nginx location / { include /etc/nginx/snippets/api.lua; try_files $uri $uri/ =404; } redis.lua from https://github.com/openresty/lua-resty-redis/releases ...