本文整理匯總了Java中redis.clients.jedis.Transaction.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.close方法的具體用法?Java Transaction.close怎麽用?Java Transaction.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redis.clients.jedis.Transaction
的用法示例。
在下文中一共展示了Transaction.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCloseable
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void testCloseable() throws IOException {
// we need to test with fresh instance of Jedis
Jedis jedis2 = new Jedis(hnp.getHost(), hnp.getPort(), 500);
jedis2.auth("foobared");
Transaction transaction = jedis2.multi();
transaction.set("a", "1");
transaction.set("b", "2");
transaction.close();
try {
transaction.exec();
fail("close should discard transaction");
} catch (JedisDataException e) {
assertTrue(e.getMessage().contains("EXEC without MULTI"));
// pass
}
}
示例2: testCloseDiscards
import redis.clients.jedis.Transaction; //導入方法依賴的package包/類
@Test
public void testCloseDiscards() throws Exception {
int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
String key = presetElementKeys.get(rnd);
String value = String.valueOf(presetElements.get(key));
Transaction transaction = jedis.multi();
Snapshot snapshot = commandTracker.snapshot();
Snapshot discardSnapshot = discardTracker.snapshot();
Snapshot txsnapshot = execTracker.snapshot();
discardSnapshot.increment();
Response<Long> added = transaction.sadd(key, value);
transaction.close();
assertNull(jedis.get(key));
txsnapshot.validate();
snapshot.validate();
discardSnapshot.validate();
}