lua-resty-redis
lua-resty-redis copied to clipboard
Unable to connect to redis instance AWS elastic cache - In-Transit Encryption (TLS) enabled
function M.connect_to_redis ()
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(10000)
local vcap_services = cjson.decode(os.getenv("ENV"))
local redis_service_name = os.getenv("REDIS")
local redis_credentials = vcap_services[redis_service_name][1].credentials;
local redis_host = redis_credentials.host
local redis_port = redis_credentials.port
local redis_password = redis_credentials.password
local ok, err = red:connect(redis_host, redis_port)
local res, err = red:auth(redis_password)
return red
end
I tried enable ssl=true by passing it as params
local options = {
ssl = true
}
local ok, err = red:connect(redis_host, redis_port, options)
And what error do you get ?
were you able to solve this ?
did you try to add ssl_verify = true in your options ? ( or maybe to false )
Using the following with AWS elastic cache + in-transit encryption enabled.
All works after adding the ssl = true.
function RedisCache.connect()
-- RedisCache credentials
local redis_host = ngx.var.redis_host or "127.0.0.1"
local redis_port = ngx.var.redis_port or 6379
local redis_pass = ngx.var.redis_pass
local redis_ssl = ngx.var.redis_ssl or false
local resty = require "resty.redis"
local redis = resty:new()
-- Connect to redis
local connected, err = redis:connect(redis_host, redis_port, {
ssl = redis_ssl
})
if not connected then
ngx.log(ngx.ERR, "could not connect to redis @" .. redis_host .. ": " .. err)
return
end
if redis_pass then
local authed, err = red:auth(redis_pass)
if not authed then
ngx.say("failed to authenticate: ", err)
return
end
end
return redis
end
Using the following with AWS elastic cache + in-transit encryption enabled.
All works after adding the
ssl = true.function RedisCache.connect() -- RedisCache credentials local redis_host = ngx.var.redis_host or "127.0.0.1" local redis_port = ngx.var.redis_port or 6379 local redis_pass = ngx.var.redis_pass local redis_ssl = ngx.var.redis_ssl or false local resty = require "resty.redis" local redis = resty:new() -- Connect to redis local connected, err = redis:connect(redis_host, redis_port, { ssl = redis_ssl }) if not connected then ngx.log(ngx.ERR, "could not connect to redis @" .. redis_host .. ": " .. err) return end if redis_pass then local authed, err = red:auth(redis_pass) if not authed then ngx.say("failed to authenticate: ", err) return end end return redis end
I also couldn't connect AWS elasticache even I set ssl option to true in connect function. It always fails when invoking auth(passwd), saying "failed to authenticate, timeout".