Lua/Redis Routing with Failover

Brian Akins brian at
Thu Feb 2 02:57:54 UTC 2012

You can't really change the upstream list on the fly. However you
could do something like this (psuedo code)

location / {
set $backend "default.backend.server";

rewrite_by_lua '
res = ngx.location.capture("/redis", { method = ngx.HTTP_PUT, body =
"srandmember setwithbackends\r\n" }
-- parse res.body to get the value
ngx.var.backend = backend_that_I_parsed
proxy_pass $backend$uri;


 location /redis {
        redis2_raw_query $echo_request_body;

If redis set has hostnames in it, you'll need to have resolver
enabled.  If you wanted, you could wrap the proxy_pass in a capture
and try the list in order until you got a good response.

More information about the nginx-devel mailing list