[英]I want to connect to Elasticcache for redis in which cluster mode is enabled. I want to connect it from golang (go-redis pkg)
[英]How to get get value from redis.Cmder in golang go-redis?
temp1Ctx, temp1Cancer := lib.GetTimeoutCtx(ctx)
pipeline := util.RedisClusterClient.Pipeline()
for _, key := range userIdRedisSlice {
pipeline.HMGet(temp1Ctx, key, userIdRedisFeature...)
}
userProfile, err := pipeline.Exec(temp1Ctx)
if err != nil {
lib.ErrorLogger.Errorf(": %v\n", err)
}
defer temp1Cancer()
// lib.ErrorLogger.Infof(": %v", userProfile)
for _, redisCmd := range userProfile {
//TODO
}
如何從中獲取價值? 我沒有找到任何文件......
要么保留HMGet
返回的具體命令類型
temp1Ctx, temp1Cancer := lib.GetTimeoutCtx(ctx)
pipeline := util.RedisClusterClient.Pipeline()
cmds := []*redis.SliceCmd{}
for _, key := range userIdRedisSlice {
cmds = append(cmds, pipeline.HMGet(temp1Ctx, key, userIdRedisFeature...))
}
if _, err := pipeline.Exec(temp1Ctx); err != nil {
lib.ErrorLogger.Errorf(": %v\n", err)
}
defer temp1Cancer()
for _, c := range cmds {
// use c.Result()
// or use c.Scan
}
或 type-assert / type-switch 將 Cmder 轉換為具體類型。
temp1Ctx, temp1Cancer := lib.GetTimeoutCtx(ctx)
pipeline := util.RedisClusterClient.Pipeline()
for _, key := range userIdRedisSlice {
pipeline.HMGet(temp1Ctx, key, userIdRedisFeature...)
}
userProfile, err := pipeline.Exec(temp1Ctx)
if err != nil {
lib.ErrorLogger.Errorf(": %v\n", err)
}
defer temp1Cancer()
for _, redisCmd := range userProfile {
switch c := redisCmd.(type) {
case *redis.SliceCmd:
// use c.Result()
// or c.Scan()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.