-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_pipeline_test.go
52 lines (43 loc) · 1.27 KB
/
cmd_pipeline_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package redisson
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
type _pipeline string
func (_pipeline) String() string { return "Pipeline" }
func testPipeline(ctx context.Context, c Cmdable) []string {
var key1, key2, value1, value2 = "key1", "key2", "value1", "value2"
var pip = func() Pipeliner {
pip := c.Pipeline()
CommandSet.P(pip).Cmd(key1, value1, 0)
CommandSet.P(pip).Cmd(key2, value2, 0)
CommandGet.P(pip).Cmd(key1)
CommandGet.P(pip).Cmd(key2)
return pip
}
res, err := pip().Exec(ctx)
So(err, ShouldBeNil)
So(res, ShouldNotBeNil)
So(len(res), ShouldEqual, 4)
So(res[0], ShouldEqual, OK)
So(res[1], ShouldEqual, OK)
So(res[2], ShouldEqual, value1)
So(res[3], ShouldEqual, value2)
var cmds []BaseCmd
cmds, err = pip().ExecCmds(ctx)
So(err, ShouldBeNil)
So(cmds, ShouldNotBeNil)
So(len(cmds), ShouldEqual, 4)
So(CommandSet.PR(cmds[0]).Val(), ShouldEqual, OK)
So(CommandSet.PR(cmds[1]).Val(), ShouldEqual, OK)
So(CommandGet.PR(cmds[2]).Val(), ShouldEqual, value1)
So(CommandGet.PR(cmds[3]).Val(), ShouldEqual, value2)
return []string{key1, key2}
}
func pipelineTestUnits() []TestUnit {
return []TestUnit{
{new(_pipeline), testPipeline},
}
}
func TestClient_Pipeline(t *testing.T) { doTestUnits(t, pipelineTestUnits) }