1

auth

docker pull redis
docker run -d -p 6379:6379 redis redis-server --requirepass mypwd

redis-cli

docker exec -it 7193a4c0a272 /bin/bash
root@7193a4c0a272:/data# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth root
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

springboot

spring.redis.password=mypwd

lua

local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(10000)
local ok, err = red:connect(redis_host, redis_port)
if ok ~= nil then
    local res, err = red:auth(redis_password)
    if res ~= nil then
       //do ....
    else
        ngx.log(ngx.ERR,"redis auth failed",err)
    end
else
    ngx.log(ngx.ERR,"can not connect to redis",err)
end

doc


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...