Lua/Redis Routing with Failover
Brian Akins
brian at akins.org
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;
}
from http://wiki.nginx.org/HttpRedis2Module#Lua_Interoperability
location /redis {
internal;
redis2_raw_query $echo_request_body;
redis2_pass 127.0.0.1:6379;
}
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