Hello!
On Sun, Oct 7, 2012 at 5:23 PM, z-ht wrote:
>
> 如何使用 redis 的认证 requirepass ?
>
> # Require clients to issue AUTH <PASSWORD> before processing any other
> # commands.
>
可以在一个 location 里使用多条 redis2_query 配置指令,把 auth 命令放在第一条,例如:
location = /t {
redis2_query auth foobared;
redis2_query flushall;
redis2_pass 127.0.0.1:$TEST_NGINX_REDIS_PORT;
}
这里假设你在 redis.conf 中配置的密码是 foobared.
当然,auth 命令的输出 "+OK\r\n" 也会出现在 location = /t 的输出里。更多细节,请参考 redis2_query
配置指令的官方文档:
http://wiki.nginx.org/HttpRedis2Module#redis2_query
值得一提的是,如果你使用 Lua 来访问 redis 的话,推荐换用 lua-resty-redis 库:
https://github.com/agentzh/lua-resty-redis
因为这个库更灵活(经常也更高效)。
Best regards,
-agentzh