Last active
March 28, 2018 22:40
-
-
Save oahayder/104aa6654b05deac2d263721cab29366 to your computer and use it in GitHub Desktop.
SSL with lua-resty-redis
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
local redis_client, err = redis:new() | |
if not redis_client then | |
log(WARN, err) | |
return nil | |
end | |
redis_client:set_timeout(_redis_timeout) | |
local ok, err = redis_client:connect(_redis_host, _redis_port) | |
if not ok then | |
log(WARN, err) | |
return nil | |
end | |
-- Performing the ssl handshake can incur significant overhead. This | |
-- shouldn't make much of an impact overall since in general the connections | |
-- will be reused as long as we get enough traffic that they do not expire. | |
local reused, err = redis_client:get_reused_times() | |
if reused == nil then | |
log(WARN, err) | |
return nil | |
elseif reused == 0 then | |
redis_client:set_timeout(_redis_timeout * 10) | |
local sock = redis_client['_sock'] | |
ok, err = sock:sslhandshake() | |
if not ok then | |
log(WARN, err) | |
return nil | |
end | |
redis_client:set_timeout(_redis_timeout) | |
end | |
-- Business logic goes here... | |
-- Set keepalive before returning to the nginx request | |
local ok, err = redis_client:set_keepalive(keepalive_timeout, pool_size) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment