Hello!
On Mon, Dec 24, 2012 at 5:36 PM, senthil wrote:
> I have built a openresty app with redis as backend
>
> I got my basic app working on heroku, but nearly every redis add-on uses
> authentication
>
[...]
> how to configure my lua redis client with authentication
>
Redis uses the "auth" command to do authentication:
http://redis.io/commands/auth
There's nothing special for this command as compared to other Redis
commands like "get" and "set".
If you're using the lua-resty-redis library in your OpenResty app,
then just use the "auth" method of your resty.redis instance. Here is
an example (tested on my side):
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return
end
local res, err = red:auth("foobared")
if not res then
ngx.say("failed to authenticate: ", err)
return
end
where we assume that you have configured your Redis server with the
password "foobared" in your redis.conf file:
requirepass foobared
If you're using the wrong password, the example above will output the
following to your HTTP client:
failed to authenticate: ERR invalid password
If you're using the ngx_redis2 module instead of lua-resty-redis2,
then just use Redis command pipelining, for example,
location = /t {
redis2_query auth foobared;
redis2_query ...;
redis2_pass ...;
}
But be prepared that the first Redis reply in the final response will
be the result of the "auth" Redis command here.
Best regards,
-agentzh