0

I have a Lua Script which Logins to the Redis and Process some Query to enable IP Based Blocking

Below is the Redis Config I am using in my Lua script and to run this script at every hit to the webserver I use the access_by_lua directive in my Nginx conference

--- Redis Configuration
local redis_host = "100.2.4.4"
local redis_port = 6379
local redis_timeout = 30
local cache_ttl     = 3600

I would like to use an environment Variable in the reds_host and the port rather than static value Any Help is appreciated

Note:

I have tried it as below, but no luck

--- Redis Configuration
local redis_host = os.getenv("redis_auth_host")
local redis_port = os.getenv("redis_auth_port")
local redis_timeout = 30
local cache_ttl     = 3600

1 Answers1

0

Redis runs Lua script in a sandbox, which disables global variables, with a few exceptions. In your case, os is a disabled global variable, so you cannot use it.

In order to avoid hard-coding the host and port, you can set them in Redis' key space, i.e. setting host and port as key-value pairs in Redis, and get them with redis.call() method.

local redis_host = redis.call("get", "host")
local redis_port = redis.call("get", "port")
for_stack
  • 21,012
  • 4
  • 35
  • 48