forked from alicebob/miniredis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_server_test.go
156 lines (129 loc) · 2.31 KB
/
cmd_server_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package miniredis
import (
"testing"
"time"
"github.com/alicebob/miniredis/v2/proto"
)
// Test DBSIZE, FLUSHDB, and FLUSHALL.
func TestCmdServer(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
// Set something
{
s.Set("aap", "niet")
s.Set("roos", "vuur")
s.DB(1).Set("noot", "mies")
}
{
mustDo(t, c,
"DBSIZE",
proto.Int(2),
)
mustOK(t, c,
"FLUSHDB",
)
must0(t, c,
"DBSIZE",
)
mustOK(t, c,
"SELECT", "1",
)
must1(t, c,
"DBSIZE",
)
mustOK(t, c,
"FLUSHALL",
)
must0(t, c,
"DBSIZE",
)
mustOK(t, c,
"SELECT", "4",
)
must0(t, c,
"DBSIZE",
)
}
{
mustOK(t, c,
"FLUSHDB", "ASYNC",
)
mustOK(t, c,
"FLUSHALL", "ASYNC",
)
}
{
mustDo(t, c,
"DBSIZE", "FOO",
proto.Error(errWrongNumber("dbsize")),
)
mustDo(t, c,
"FLUSHDB", "FOO",
proto.Error("ERR syntax error"),
)
mustDo(t, c,
"FLUSHDB", "ASYNC", "FOO",
proto.Error("ERR syntax error"),
)
mustDo(t, c,
"FLUSHALL", "FOO",
proto.Error("ERR syntax error"),
)
mustDo(t, c,
"FLUSHALL", "ASYNC", "FOO",
proto.Error("ERR syntax error"),
)
mustDo(t, c,
"FLUSHALL", "ASYNC", "ASYNC",
proto.Error("ERR syntax error"),
)
}
}
// Test TIME
func TestCmdServerTime(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
_, err = c.Do("TIME")
ok(t, err)
s.SetTime(time.Unix(100, 123456789))
mustDo(t, c,
"TIME",
proto.Strings("100", "123456"),
)
mustDo(t, c,
"TIME", "FOO",
proto.Error(errWrongNumber("time")),
)
}
// Test Memory Usage
func TestCmdServerMemoryUsage(t *testing.T) {
s, err := Run()
ok(t, err)
defer s.Close()
c, err := proto.Dial(s.Addr())
ok(t, err)
defer c.Close()
c.Do("SET", "foo", "bar")
mustDo(t, c,
"PFADD", "h", "aap", "noot", "mies",
proto.Int(1),
)
// Intended only for having metrics not to be 1:1 Redis
mustDo(t, c,
"MEMORY", "USAGE", "foo",
proto.Int(19), // normally, with Redis it should be 56 but we don't have the same overhead as Redis
)
// Intended only for having metrics not to be 1:1 Redis
mustDo(t, c,
"MEMORY", "USAGE", "h",
proto.Int(124), // normally, with Redis it should be 56 but we don't have the same overhead as Redis
)
}