I'm trying to connect to my Redis server using Go and redigo with a URI that works on another application, written in Java with lettuce. On the Go project, I'm getting the error
NOAUTH Authentication required.
My redis.conf
has requirepass true
, and I pass the password in the URI. Here's how I connect:
conn, err := redis.DialURL("redis://MySecurePassword@localhost:6666/0")
if err != nil {
log.Fatal("Not able to connect to Redis")
}
No errors there. The error shows when I try to run a command to retrieve data.
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)
}
Am I using redigo's API improperly? How can I make it connect?