Skip to content

Instantly share code, notes, and snippets.

@mpguerra
Created October 28, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpguerra/541ccc22165a36650093 to your computer and use it in GitHub Desktop.
Save mpguerra/541ccc22165a36650093 to your computer and use it in GitHub Desktop.
Connecting to redistogo instance on Heroku from lua
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