@edmond_brakus
To serve a Redis key with Nginx, you can use a Lua script along with the Nginx Lua module. Here is a basic example of how you can achieve this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
local resty_redis = require "resty.redis" local redis = resty_redis:new() redis:set_timeout(1000) -- 1 second timeout local ok, err = redis:connect("127.0.0.1", 6379) if not ok then ngx.log(ngx.ERR, "failed to connect to Redis: ", err) return ngx.exit(500) end local res, err = redis:get("your_redis_key") if not res then ngx.log(ngx.ERR, "failed to get Redis key: ", err) return ngx.exit(500) end redis:set_keepalive(10000, 100) -- keep connection alive for 10 seconds ngx.say(res) |
1 2 3 4 |
location /redis { default_type 'text/plain'; content_by_lua_file /path/to/your/lua/script.lua; } |
Now, when you access the URL /redis on your Nginx server, the Lua script will connect to Redis, fetch the value of the specified key, and return it to the client.