@@ -2,6 +2,7 @@ package redis
2
2
3
3
import (
4
4
"context"
5
+ "errors"
5
6
)
6
7
7
8
type pipelineExecer func (context.Context , []Cmder ) error
@@ -21,10 +22,21 @@ type pipelineExecer func(context.Context, []Cmder) error
21
22
// depends of your batch size and/or use TxPipeline.
22
23
type Pipeliner interface {
23
24
StatefulCmdable
25
+
26
+ // Len is to obtain the number of commands in the pipeline that have not yet been executed.
24
27
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.
25
31
Do (ctx context.Context , args ... interface {}) * Cmd
32
+
33
+ // Process is to put the commands to be executed into the pipeline buffer.
26
34
Process (ctx context.Context , cmd Cmder ) error
35
+
36
+ // Discard is to discard all commands in the cache that have not yet been executed.
27
37
Discard ()
38
+
39
+ // Exec is to send all the commands buffered in the pipeline to the redis-server.
28
40
Exec (ctx context.Context ) ([]Cmder , error )
29
41
}
30
42
@@ -54,6 +66,10 @@ func (c *Pipeline) Len() int {
54
66
// Do queues the custom command for later execution.
55
67
func (c * Pipeline ) Do (ctx context.Context , args ... interface {}) * Cmd {
56
68
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
+ }
57
73
_ = c .Process (ctx , cmd )
58
74
return cmd
59
75
}
0 commit comments