-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathtx_test.go
181 lines (162 loc) · 3.69 KB
/
tx_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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package main
import (
"testing"
)
func TestTx(t *testing.T) {
skip(t)
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("SET", "AAP", "1")
c.Do("GET", "AAP")
c.Do("EXEC")
c.Do("GET", "AAP")
})
// empty
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("EXEC")
})
// err: Double MULTI
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Error("nested", "MULTI")
})
// err: No MULTI
testRaw(t, func(c *client) {
c.Error("without MULTI", "EXEC")
})
// Errors in the MULTI sequence
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("SET", "foo", "bar")
c.Error("wrong number", "SET", "foo")
c.Do("SET", "foo", "bar")
c.Error("EXECABORT", "EXEC")
})
// Simple WATCH
testRaw(t, func(c *client) {
c.Do("SET", "foo", "bar")
c.Do("WATCH", "foo")
c.Do("MULTI")
c.Do("GET", "foo")
c.Do("EXEC")
})
// Simple UNWATCH
testRaw(t, func(c *client) {
c.Do("SET", "foo", "bar")
c.Do("WATCH", "foo")
c.Do("UNWATCH")
c.Do("MULTI")
c.Do("GET", "foo")
c.Do("EXEC")
})
// UNWATCH in a MULTI. Yep. Weird.
testRaw(t, func(c *client) {
c.Do("WATCH", "foo")
c.Do("MULTI")
c.Do("UNWATCH") // Valid. Somehow.
c.Do("EXEC")
})
// Test whether all these commands support transactions.
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("GET", "str")
c.Do("GETEX", "str")
c.Do("SET", "str", "bar")
c.Do("SETNX", "str", "bar")
c.Do("GETSET", "str", "bar")
c.Do("MGET", "str", "bar")
c.Do("MSET", "str", "bar")
c.Do("MSETNX", "str", "bar")
c.Do("SETEX", "str", "12", "newv")
c.Do("PSETEX", "str", "12", "newv")
c.Do("STRLEN", "str")
c.Do("APPEND", "str", "more")
c.Do("GETRANGE", "str", "0", "2")
c.Do("SETRANGE", "str", "0", "B")
c.Do("EXEC")
c.Do("GET", "str")
})
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("SET", "bits", "\xff\x00")
c.Do("BITCOUNT", "bits")
c.Do("BITOP", "OR", "bits", "bits", "nosuch")
c.Do("BITPOS", "bits", "1")
c.Do("GETBIT", "bits", "12")
c.Do("SETBIT", "bits", "12", "1")
c.Do("EXEC")
c.Do("GET", "bits")
})
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("INCR", "number")
c.Do("INCRBY", "number", "12")
c.Do("INCRBYFLOAT", "number", "12.2")
c.Do("DECR", "number")
c.Do("GET", "number")
c.Do("DECRBY", "number", "2")
c.Do("GET", "number")
})
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("HSET", "hash", "foo", "bar")
c.Do("HDEL", "hash", "foo")
c.Do("HEXISTS", "hash", "foo")
c.Do("HSET", "hash", "foo", "bar22")
c.Do("HSETNX", "hash", "foo", "bar22")
c.Do("HGET", "hash", "foo")
c.Do("HMGET", "hash", "foo", "baz")
c.Do("HLEN", "hash")
c.Do("HGETALL", "hash")
c.Do("HKEYS", "hash")
c.Do("HVALS", "hash")
})
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("SET", "key", "foo")
c.Do("TYPE", "key")
c.Do("EXPIRE", "key", "12")
c.Do("TTL", "key")
c.Do("PEXPIRE", "key", "12")
c.Do("PTTL", "key")
c.Do("PERSIST", "key")
c.Do("DEL", "key")
c.Do("TYPE", "key")
c.Do("EXEC")
})
// BITOP OPs are checked after the transaction.
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("BITOP", "BROKEN", "str", "")
c.Do("EXEC")
})
// fail on invalid command
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Error("wrong number", "GET")
c.Error("Transaction discarded", "EXEC")
})
/* FIXME
// fail on unknown command
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Do("NOSUCH")
c.Do("EXEC")
})
*/
// failed EXEC cleaned up the tx
testRaw(t, func(c *client) {
c.Do("MULTI")
c.Error("wrong number", "GET")
c.Error("Transaction discarded", "EXEC")
c.Do("MULTI")
})
testRaw2(t, func(c1, c2 *client) {
c1.Do("WATCH", "foo")
c1.Do("MULTI")
c2.Do("SET", "foo", "12")
c2.Error("without", "EXEC") // nil
c1.Do("EXEC") // 0-length
})
}