Created
October 28, 2014 10:32
-
-
Save mpguerra/541ccc22165a36650093 to your computer and use it in GitHub Desktop.
Connecting to redistogo instance on Heroku from lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function M.connect_redis(red) | |
redisurl = os.getenv("REDISTOGO_URL") | |
redisurl_connect = string.split(redisurl, ":")[3] | |
redisurl_user = string.split(redisurl_connect, "@")[1] | |
redisurl_host = string.split(redisurl_connect, "@")[2] | |
redisurl_port = tonumber(string.split(redisurl, ":")[4]) | |
local ok, err = red:connect(redisurl_host, redisurl_port) | |
if not ok then | |
ngx.say("failed to connect: ", err) | |
ngx.exit(ngx.HTTP_OK) | |
end | |
local res, err = red:auth(redisurl_user) | |
if not res then | |
ngx.say("failed to authenticate: ", err) | |
return | |
end | |
return ok, err | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment