]> git.saurik.com Git - redis.git/blame - tests/unit/multi.tcl
Test: make sure EXEC fails after previous transaction errors.
[redis.git] / tests / unit / multi.tcl
CommitLineData
37d978d9 1start_server {tags {"multi"}} {
2 test {MUTLI / EXEC basics} {
3 r del mylist
4 r rpush mylist a
5 r rpush mylist b
6 r rpush mylist c
7 r multi
8 set v1 [r lrange mylist 0 -1]
9 set v2 [r ping]
10 set v3 [r exec]
11 list $v1 $v2 $v3
12 } {QUEUED QUEUED {{a b c} PONG}}
13
14 test {DISCARD} {
15 r del mylist
16 r rpush mylist a
17 r rpush mylist b
18 r rpush mylist c
19 r multi
20 set v1 [r del mylist]
21 set v2 [r discard]
22 set v3 [r lrange mylist 0 -1]
23 list $v1 $v2 $v3
24 } {QUEUED OK {a b c}}
25
26 test {Nested MULTI are not allowed} {
27 set err {}
28 r multi
29 catch {[r multi]} err
30 r exec
31 set _ $err
32 } {*ERR MULTI*}
33
34 test {MULTI where commands alter argc/argv} {
35 r sadd myset a
36 r multi
37 r spop myset
38 list [r exec] [r exists myset]
39 } {a 0}
40
41 test {WATCH inside MULTI is not allowed} {
42 set err {}
43 r multi
44 catch {[r watch x]} err
45 r exec
46 set _ $err
47 } {*ERR WATCH*}
48
52bd3d8a 49 test {EXEC fails if there are errors while queueing commands #1} {
50 r del foo1 foo2
51 r multi
52 r set foo1 bar1
53 catch {r non-existing-command}
54 r set foo2 bar2
55 catch {r exec} e
56 assert_match {EXECABORT*} $e
57 list [r exists foo1] [r exists foo2]
58 } {0 0}
59
60 test {EXEC fails if there are errors while queueing commands #2} {
61 set rd [redis_deferring_client]
62 r del foo1 foo2
63 r multi
64 r set foo1 bar1
65 $rd config set maxmemory 1
66 catch {r lpush mylist myvalue}
67 $rd config set maxmemory 0
68 r set foo2 bar2
69 catch {r exec} e
70 assert_match {EXECABORT*} $e
71 assert {[$rd read] eq {OK}}
72 assert {[$rd read] eq {OK}}
73 $rd close
74 list [r exists foo1] [r exists foo2]
75 } {0 0}
76
c20c189d 77 test {EXEC works on WATCHed key not modified} {
78 r watch x y z
79 r watch k
80 r multi
81 r ping
82 r exec
83 } {PONG}
84
85 test {EXEC fail on WATCHed key modified (1 key of 1 watched)} {
86 r set x 30
87 r watch x
88 r set x 40
89 r multi
90 r ping
91 r exec
92 } {}
93
94 test {EXEC fail on WATCHed key modified (1 key of 5 watched)} {
95 r set x 30
96 r watch a b x k z
97 r set x 40
98 r multi
99 r ping
100 r exec
101 } {}
102
a0bf8d0a
MK
103 test {EXEC fail on WATCHed key modified by SORT with STORE even if the result is empty} {
104 r flushdb
105 r lpush foo bar
106 r watch foo
107 r sort emptylist store foo
108 r multi
109 r ping
110 r exec
111 } {}
112
c20c189d 113 test {After successful EXEC key is no longer watched} {
114 r set x 30
115 r watch x
116 r multi
117 r ping
118 r exec
119 r set x 40
120 r multi
121 r ping
122 r exec
123 } {PONG}
124
125 test {After failed EXEC key is no longer watched} {
126 r set x 30
127 r watch x
128 r set x 40
129 r multi
130 r ping
131 r exec
132 r set x 40
133 r multi
134 r ping
135 r exec
136 } {PONG}
137
138 test {It is possible to UNWATCH} {
139 r set x 30
140 r watch x
141 r set x 40
142 r unwatch
143 r multi
144 r ping
145 r exec
146 } {PONG}
147
148 test {UNWATCH when there is nothing watched works as expected} {
149 r unwatch
150 } {OK}
9b30e1a2 151
152 test {FLUSHALL is able to touch the watched keys} {
153 r set x 30
154 r watch x
155 r flushall
156 r multi
157 r ping
158 r exec
159 } {}
160
161 test {FLUSHALL does not touch non affected keys} {
162 r del x
163 r watch x
164 r flushall
165 r multi
166 r ping
167 r exec
168 } {PONG}
169
170 test {FLUSHDB is able to touch the watched keys} {
171 r set x 30
172 r watch x
173 r flushdb
174 r multi
175 r ping
176 r exec
177 } {}
178
179 test {FLUSHDB does not touch non affected keys} {
180 r del x
181 r watch x
182 r flushdb
183 r multi
184 r ping
185 r exec
186 } {PONG}
187
188 test {WATCH is able to remember the DB a key belongs to} {
189 r select 5
190 r set x 30
191 r watch x
192 r select 1
193 r set x 10
194 r select 5
195 r multi
196 r ping
197 r exec
198 } {PONG}
b7a8daef 199
200 test {WATCH will consider touched keys target of EXPIRE} {
201 r del x
202 r set x foo
203 r watch x
204 r expire x 10
205 r multi
206 r ping
207 r exec
208 } {}
209
210 test {WATCH will not consider touched expired keys} {
211 r del x
212 r set x foo
674df1ee 213 r expire x 1
b7a8daef 214 r watch x
674df1ee 215 after 1100
b7a8daef 216 r multi
217 r ping
218 r exec
219 } {PONG}
674df1ee 220
221 test {DISCARD should clear the WATCH dirty flag on the client} {
222 r watch x
223 r set x 10
224 r multi
225 r discard
226 r multi
227 r incr x
228 r exec
229 } {11}
230
231 test {DISCARD should UNWATCH all the keys} {
232 r watch x
233 r set x 10
234 r multi
235 r discard
236 r set x 10
237 r multi
238 r incr x
239 r exec
240 } {11}
c20c189d 241}