Hi, I'm not sure how to get values from pipeline.Exec()
.
cmd.Val()
results in type redis.Cmder has no field or method Val
It's very odd because reflect.TypeOf(cmd)
does indeed return *redis.StringCmd
, and both the docs and the code quite clearly indicate that the Val()
method should be working.
Hi,
I updated pipelined example to show how to get *redis.StringCmd from redis.Cmder: http://godoc.org/github.com/vmihailenco/redis/v2#example-Client-Pipelined . Also take a look at http://godoc.org/github.com/vmihailenco/redis/v2#example-Pipeline , which can be useful in your case.
Thanks for the quick reply! I'm new to Go so I didn't consider type assertion. I will try this out tomorrow.
You are welcome.
the follow link broken,
http://godoc.org/github.com/vmihailenco/redis/v2#example-Client-Pipelined http://godoc.org/github.com/vmihailenco/redis/v2#example-Pipeline
I Got A Error ‘redis: nil’ when i execute code as below:
pip := redisClient.Pipeline()
if _, err := pip.Ping().Result(); err != nil {
log.Errorln("redis pipeline ping failed, err:", err.Error())
} else {
//here is ok
log.Errorln("redis pipeline ping ok")
}
results := make([]*redis.StringCmd, 0)
for _, key := range keys {
results = append(results, pip.Get(key))
}
_, err := pip.Exec()
if err != nil {
return make([]int64, len(keys)), errors.Wrapf(err, "Redis Pipeline Execute Error")
}
You have to check if the err is equal to redis.Nil
res, err := pipeline.Exec(ctx)
if err != redis.Nil {
log.Fatal(err)
}
Most helpful comment
the follow link broken,
http://godoc.org/github.com/vmihailenco/redis/v2#example-Client-Pipelined http://godoc.org/github.com/vmihailenco/redis/v2#example-Pipeline
I Got A Error ‘redis: nil’ when i execute code as below: