我尝试与REDIS SENTINEL连接的代码。由于我是Golang的新手,所以想弄清楚我怎么了? REDIS SENTINEL已配置并正常工作。
package main
import (
"fmt"
"github.com/go-redis/redis"
)
func main() {
rdb:=redis.NewFailoverClient(&redis.FailoverOptions(
MasterName: "mymaster",
SentinelAddrs: "XXX.XXX.XXX.XXX:26379","XXX.XXX.XXX.XXX:26379","XXX.XXX.XXX.XXX:26379",
))
rdb.Ping()
}
运行:
$ go run redis.go
**# command-line-arguments**
>./redif.go:11:12: syntax error: unexpected :, expecting comma or )**
答案 0 :(得分:0)
该错误表明您使用了错误的格式化字符串切片。
参见“ go-redis” pkg中的FailoverOption{}。它说.SentinelAddrs
是[]string
类型。
rdb:=redis.NewFailoverClient(&redis.FailoverOptions(
MasterName: "mymaster",
SentinelAddrs: []string{"XXX.XXX.XXX.XXX:26379","XXX.XXX.XXX.XXX:26379","XXX.XXX.XXX.XXX:26379"},
))