use of org.redisson.api.RTransaction in project redisson by redisson.
the class TransactionalBean2 method testPropagationRequired.
@Transactional
public void testPropagationRequired() {
RTransaction transaction = transactionManager.getCurrentTransaction();
transaction.getMap("tr3").put("2", "4");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class TransactionalBean2 method testPropagationRequiredWithException.
@Transactional
public void testPropagationRequiredWithException() {
RTransaction transaction = transactionManager.getCurrentTransaction();
transaction.getMap("tr5").put("2", "4");
throw new IllegalStateException();
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionManager method doBegin.
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
RedissonTransactionObject tObject = (RedissonTransactionObject) transaction;
if (tObject.getTransactionHolder() == null) {
int timeout = determineTimeout(definition);
TransactionOptions options = TransactionOptions.defaults();
if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
options.timeout(timeout, TimeUnit.SECONDS);
}
RTransaction trans = redisson.createTransaction(options);
RedissonTransactionHolder holder = new RedissonTransactionHolder();
holder.setTransaction(trans);
tObject.setTransactionHolder(holder);
TransactionSynchronizationManager.bindResource(redisson, holder);
}
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalBucketsTest method testSet.
@Test
public void testSet() {
RBucket<String> b1 = redisson.getBucket("test1");
b1.set("1");
RBucket<String> b2 = redisson.getBucket("test2");
b2.set("2");
RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
RBuckets buckets = transaction.getBuckets();
Map<String, Object> bbs = new LinkedHashMap<>();
bbs.put("test1", "11");
bbs.put("test2", "22");
buckets.set(bbs);
Map<String, Object> newBuckets = buckets.get("test1", "test2");
assertThat(newBuckets).isEqualTo(bbs);
transaction.commit();
assertThat(redisson.getBuckets().get("test1", "test2")).isEqualTo(bbs);
assertThat(redisson.getKeys().count()).isEqualTo(2);
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalBucketsTest method testTrySet.
@Test
public void testTrySet() {
redisson.getBucket("test1").set("1");
redisson.getBucket("test2").set("2");
RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
RBuckets buckets = transaction.getBuckets();
Map<String, Object> bbs1 = new LinkedHashMap<>();
bbs1.put("test1", "10");
bbs1.put("test2", "20");
assertThat(buckets.trySet(bbs1)).isFalse();
assertThat(redisson.getKeys().delete("test1", "test2")).isEqualTo(2);
Map<String, Object> bbs2 = new LinkedHashMap<>();
bbs2.put("test1", "11");
bbs2.put("test2", "22");
assertThat(buckets.trySet(bbs2)).isTrue();
Map<String, Object> bbs3 = new LinkedHashMap<>();
bbs3.put("test1", "13");
bbs3.put("test2", "23");
assertThat(buckets.trySet(bbs3)).isFalse();
System.out.println("commit " + Thread.currentThread().getId());
transaction.commit();
redisson.getKeys().getKeys().forEach(x -> System.out.println(x));
// assertThat(redisson.getBuckets().get("test1", "test2")).isEqualTo(bbs2);
assertThat(redisson.getKeys().count()).isEqualTo(2);
}
Aggregations