As the title, and the code like this:
var stringSliceCmd *redis.StringSliceCmd // stringSliceCmd is the result of Redis operation
_, err := RedisCli.Pipelined(ctx, func(pipe redis.Pipeliner) error {
stringSliceCmd = pipe.LRange(ctx, "log-oss", 0, 1) // step one
pipe.LTrim(ctx, "log-oss", 2, -1) // step two
err := testHandleMessage(stringSliceCmd) // step three
if err != nil {
log.Errorf("HandleMessage err: %v", err)
return err
}
return nil
})
Explanation:
Now I need to do three steps, and hopefully do it atomically.
Step one can get the result stringSliceCmd from redis, step two is another redis operation,
and step three is a function that need the result stringSliceCmd. And if one of three steps failed, then return error.
But if I code it as above, the result stringSliceCmd if nil. What should I do?