go-redis/redis · error

redis: please enter the command to be executed

Error message

redis: please enter the command to be executed

What it means

Set on the returned *redis.Cmd when Pipeline.Do is called with zero arguments. Pipeline.Do queues a custom command from variadic args; with none there is no command to queue, so the cmd is returned pre-errored. This is a client-side guard, not a Redis server error.

Source

Thrown at pipeline.go:76

	exec pipelineExecer
	cmds []Cmder
}

func (c *Pipeline) init() {
	c.cmdable = c.Process
	c.statefulCmdable = c.Process
}

// Len returns the number of queued commands.
func (c *Pipeline) Len() int {
	return len(c.cmds)
}

// Do queues the custom command for later execution.
func (c *Pipeline) Do(ctx context.Context, args ...interface{}) *Cmd {
	cmd := NewCmd(ctx, args...)
	if len(args) == 0 {
		cmd.SetErr(errors.New("redis: please enter the command to be executed"))
		return cmd
	}
	_ = c.Process(ctx, cmd)
	return cmd
}

// Process queues the cmd for later execution.
func (c *Pipeline) Process(ctx context.Context, cmd Cmder) error {
	return c.BatchProcess(ctx, cmd)
}

// BatchProcess queues multiple cmds for later execution.
func (c *Pipeline) BatchProcess(ctx context.Context, cmd ...Cmder) error {
	c.cmds = append(c.cmds, cmd...)
	return nil
}

// Discard resets the pipeline and discards queued commands.

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Guard the Do call: only invoke it when you have at least one argument (the command name).
  2. Check len(args) > 0 before pipe.Do(ctx, args...).
  3. Review the code that assembles the args slice to ensure the command name is always included.

Example fix

// before
pipe.Do(ctx, cmdArgs...) // cmdArgs is empty

// after
if len(cmdArgs) == 0 {
    return errors.New("no command to execute")
}
pipe.Do(ctx, cmdArgs...)
Defensive patterns

Strategy: validation

Validate before calling

func pipeDo(pipe redis.Pipeliner, ctx context.Context, args ...interface{}) *redis.Cmd {
    if len(args) == 0 {
        cmd := redis.NewCmd(ctx)
        cmd.SetErr(errors.New("no command provided"))
        return cmd
    }
    return pipe.Do(ctx, args...)
}

Prevention

When it happens

Trigger: Calling pipe.Do(ctx) with no command name or arguments, e.g. an empty Do call on a Pipeline. Common when args are computed dynamically and the slice is empty (pipe.Do(ctx, dynamicArgs...) where dynamicArgs is nil/empty).

Common situations: Dynamic command building where the args slice can be empty due to upstream logic. Copy-paste from a Do(ctx, "GET", key) pattern with the args accidentally dropped. Loop bodies that build commands conditionally and sometimes emit nothing.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/cf90cff643563ee9.json. Report an issue: GitHub.