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」。 –