I do the following to do a get the value from a key.
Every time, ngix will call the same script again and I am wondering how can it be optimized as the connection will not change. I would like to have some insight how can I ruse the same redis connection. Any help is much appreciated.
-- REDIS Connection
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(100) -- 100 ms
local redis_host = os.getenv("CSP_REDIS_HOST")
if not redis_host then redis_host = "127.0.0.1" end
local redis_port = os.getenv("CSP_REDIS_PORT")
if not redis_port then redis_port = 6379 end
local res, err = red:connect(redis_host, redis_port)
... The above code is same all the time and only the key for look up is different.
res, err = red:hget(key, "proxyPass")