Skip to content

Commit ac0c537

Browse files
author
Vitalii Cherkashyn
committed
throw exception during transaction execution
1 parent a9d7686 commit ac0c537

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

redis/transaction.java.snippet

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import redis.clients.jedis.Jedis;
2+
import redis.clients.jedis.Pipeline;
3+
import redis.clients.jedis.Response;
4+
import redis.clients.jedis.Transaction;
5+
import redis.clients.jedis.exceptions.JedisDataException;
6+
7+
8+
Transaction t = jedis.multi();
9+
10+
Response<Long> hsetResponse = t.hset(statusKey, "available", "true");
11+
Response<Long> expireResponse = t.expire(statusKey, 1000);
12+
Response<Long> saddResponse = t.sadd(availableKey,
13+
String.valueOf(siteId));
14+
15+
t.exec();
16+
// !!! IMPORTANT
17+
// if something wrong with operation - exception will be thrown during Response.get()
18+
19+
assertThat(hsetResponse.get(), is(1L));
20+
assertThat(expireResponse.get(), is(1L));
21+
assertThat(saddResponse.get(), is(1L));
22+

0 commit comments

Comments
 (0)