@@ -2,6 +2,7 @@ package redis
22
33import (
44 "context"
5+ "errors"
56)
67
78type pipelineExecer func (context.Context , []Cmder ) error
@@ -21,10 +22,21 @@ type pipelineExecer func(context.Context, []Cmder) error
2122// depends of your batch size and/or use TxPipeline.
2223type Pipeliner interface {
2324 StatefulCmdable
25+
26+ // Len is to obtain the number of commands in the pipeline that have not yet been executed.
2427 Len () int
28+
29+ // Do is an API for executing any command.
30+ // If a certain Redis command is not yet supported, you can use Do to execute it.
2531 Do (ctx context.Context , args ... interface {}) * Cmd
32+
33+ // Process is to put the commands to be executed into the pipeline buffer.
2634 Process (ctx context.Context , cmd Cmder ) error
35+
36+ // Discard is to discard all commands in the cache that have not yet been executed.
2737 Discard ()
38+
39+ // Exec is to send all the commands buffered in the pipeline to the redis-server.
2840 Exec (ctx context.Context ) ([]Cmder , error )
2941}
3042
@@ -54,6 +66,10 @@ func (c *Pipeline) Len() int {
5466// Do queues the custom command for later execution.
5567func (c * Pipeline ) Do (ctx context.Context , args ... interface {}) * Cmd {
5668 cmd := NewCmd (ctx , args ... )
69+ if len (args ) == 0 {
70+ cmd .SetErr (errors .New ("redis: please enter the command to be executed" ))
71+ return cmd
72+ }
5773 _ = c .Process (ctx , cmd )
5874 return cmd
5975}
0 commit comments