我使用 newPool 来初始化 redis.Pool
var (
Pool *redis.Pool
)
func newPool(server string) *redis.Pool {
return &redis.Pool{
MaxIdle: 3,
IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) {
redisPwd, _ := misc.AppConf.Get("redis_pwd") // get password from config
conn, err := redis.Dial("tcp", server, redis.DialPassword(redisPwd))
if err != nil {
return nil, err
}
return conn, nil
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
}
尝试连接redis DB
func TestRedis(t *testing.T) {
InitRedis()
redisConn := Pool.Get()
keys, err := redis.Strings(redisConn.Do("kEYS", "*"))
if err != nil {
t.Fatal(err)
}
fmt.Printf("%v\n", keys)
time.Sleep(time.Hour)
}
连接3.0版本redis DB时返回错误: ERR Client sent AUTH, but no password is set
错误消息描述了问题。 跳过发送密码或在服务器的配置中设置密码。
@garyburd我也有同样的问题。 我已经在redis.windows.conf
中设置了requirepass
$ 并使用该配置运行redis.exe
。 当我进行池连接时,它说: Redis set failed: ERR Client sent AUTH, but no password is set
没有设置密码
您是否在配置文件中设置了密码,服务器是否使用了该配置文件?
没有设置密码
你在配置文件中设置了密码吗?
对不起这是我的错。 我混淆了我的两个 Redis 服务器。 现在一切正常。
最有用的评论
您是否在配置文件中设置了密码,服务器是否使用了该配置文件?