File tree 2 files changed +29
-0
lines changed
main/java/redis/clients/jedis
test/java/redis/clients/jedis/tests
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -104,12 +104,18 @@ public List<Object> syncAndReturnAll() {
104
104
}
105
105
106
106
public Response <String > discard () {
107
+ if (currentMulti == null )
108
+ throw new JedisDataException ("DISCARD without MULTI" );
109
+
107
110
client .discard ();
108
111
currentMulti = null ;
109
112
return getResponse (BuilderFactory .STRING );
110
113
}
111
114
112
115
public Response <List <Object >> exec () {
116
+ if (currentMulti == null )
117
+ throw new JedisDataException ("EXEC without MULTI" );
118
+
113
119
client .exec ();
114
120
Response <List <Object >> response = super .getResponse (currentMulti );
115
121
currentMulti .setResponseDependency (response );
@@ -118,6 +124,9 @@ public Response<List<Object>> exec() {
118
124
}
119
125
120
126
public Response <String > multi () {
127
+ if (currentMulti != null )
128
+ throw new JedisDataException ("MULTI calls can not be nested" );
129
+
121
130
client .multi ();
122
131
Response <String > response = getResponse (BuilderFactory .STRING ); // Expecting
123
132
// OK
Original file line number Diff line number Diff line change @@ -272,6 +272,26 @@ public void multiWithSync() {
272
272
assertEquals ("world" , r3 .get ());
273
273
}
274
274
275
+ @ Test (expected = JedisDataException .class )
276
+ public void pipelineExecShoudThrowJedisDataExceptionWhenNotInMulti () {
277
+ Pipeline pipeline = jedis .pipelined ();
278
+ pipeline .exec ();
279
+ }
280
+
281
+ @ Test (expected = JedisDataException .class )
282
+ public void pipelineDiscardShoudThrowJedisDataExceptionWhenNotInMulti () {
283
+ Pipeline pipeline = jedis .pipelined ();
284
+ pipeline .discard ();
285
+ }
286
+
287
+ @ Test (expected = JedisDataException .class )
288
+ public void pipelineMultiShoudThrowJedisDataExceptionWhenAlreadyInMulti () {
289
+ Pipeline pipeline = jedis .pipelined ();
290
+ pipeline .multi ();
291
+ pipeline .set ("foo" , "3" );
292
+ pipeline .multi ();
293
+ }
294
+
275
295
@ Test
276
296
public void testDiscardInPipeline () {
277
297
Pipeline pipeline = jedis .pipelined ();
You can’t perform that action at this time.
0 commit comments