如何在Golang中将*redis.SliceCmd转换为[]string?

huangapple go评论73阅读模式
英文:

How to convert *redis.SliceCmd to []string in golang?

问题

我使用github.com/go-redis/redis/v8,我想从Redis中获取值:

userProfile := util.RedisClusterClient.HMGet(redisCtx, redisUserProfileHashkey, userIdSlice...)

但是HMGet返回的是一个*redis.SliceCmd,而不是一个[]string。为什么这个模块设计成这样?我如何获取一个[]string类型的值?

英文:

I use github.com/go-redis/redis/v8 , and I want to get the value in redis :

userProfile := util.RedisClusterClient.HMGet(redisCtx, redisUserProfileHashkey, userIdSlice...)

But the HMGet return a *redis.SliceCmd , not a []string . Why does the module design this ? How can I get a []string

答案1

得分: 3

所有不同的*Cmd返回值都有一个cmd.Result()方法用于访问结果,以及一个cmd.Err()方法用于测试是否成功。

请参阅https://pkg.go.dev/github.com/go-redis/redis/v8#SliceCmd

英文:

All the various *Cmd return values have a cmd.Result() method for accessing the result, as well as an cmd.Err() method for testing for success.

See https://pkg.go.dev/github.com/go-redis/redis/v8#SliceCmd

huangapple
  • 本文由 发表于 2021年6月29日 22:21:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/68180607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定