0
我试图使用Go和redigo连接到我的Redis服务器,并使用可在另一个应用程序上使用的URI编写,其编码为lettuce。在围棋项目中,我得到了错误Go和Redisgo:DialURL错误:NOAUTH需要身份验证
NOAUTH Authentication required.
我redis.conf
有requirepass true
,和我通过URI中的密码。以下是我如何连接:
conn, err := redis.DialURL("redis://[email protected]:6666/0")
if err != nil {
log.Fatal("Not able to connect to Redis")
}
那里没有错误。当我尝试运行命令来检索数据时,显示错误。
writeOrErr(&b, conn, "HGETALL", "mykey")
// Wrapper for redis.Conn.Do that writes the result to a buffer or reports the error
func writeOrErr(b *bytes.Buffer, conn redis.Conn, cmd string, key string) string {
result, err := conn.Do(cmd, key)
if err != nil {
// !!! THE ERROR HAPPENS HERE !!!
log.Fatalf("Couldn't run %s \"%s\" | Error: %s", cmd, key, err.Error())
}
// Retrieve data
_, err = b.WriteString(result.(string))
if err != nil {
log.Fatal("Couldn't write result to string for " + key)
}
return result.(string)
}
我使用redigo的API不当?我怎样才能连接?
您是否也可以显示命令来运行数据? –
@CeriseLimón我用显式值更新了'DialURL'。 – sargas
该URL与[redis URI scheme specification](https://www.iana.org/assignments/uri-schemes/prov/redis)不匹配。 userinfo字段的格式应该是“user:password”。 –