0
    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
    }

如何从中获得价值?我没有找到任何文件.......

4

1 回答 1

2

要么保留返回的具体命令类型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()
    }
}
于 2021-07-01T11:30:00.257 回答