Search in sources :

Example 11 with RTransaction

use of org.redisson.api.RTransaction in project redisson by redisson.

the class RedissonTransactionalBucketTest method testGetAndSet.

@Test
public void testGetAndSet() {
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    assertThat(bucket.getAndSet("0")).isEqualTo("123");
    assertThat(bucket.get()).isEqualTo("0");
    assertThat(bucket.getAndSet("324")).isEqualTo("0");
    transaction.commit();
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    assertThat(b.get()).isEqualTo("324");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 12 with RTransaction

use of org.redisson.api.RTransaction in project redisson by redisson.

the class RedissonTransactionalBucketTest method testSet.

@Test
public void testSet() {
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    bucket.set("234");
    assertThat(bucket.get()).isEqualTo("234");
    transaction.commit();
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    assertThat(b.get()).isEqualTo("234");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 13 with RTransaction

use of org.redisson.api.RTransaction in project redisson by redisson.

the class RedissonTransactionalLocalCachedMapTest method testPutRemove.

@Test
public void testPutRemove() {
    RLocalCachedMap<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m1.put("1", "2");
    m1.put("3", "4");
    RLocalCachedMap<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m2.get("1");
    m2.get("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = transaction.getLocalCachedMap(m1);
    assertThat(map.get("1")).isEqualTo("2");
    assertThat(map.remove("3")).isEqualTo("4");
    assertThat(map.put("3", "5")).isNull();
    assertThat(map.get("3")).isEqualTo("5");
    assertThat(m1.get("3")).isEqualTo("4");
    assertThat(m2.get("3")).isEqualTo("4");
    transaction.commit();
    assertThat(m1.get("1")).isEqualTo("2");
    assertThat(m1.get("3")).isEqualTo("5");
    assertThat(m2.get("1")).isEqualTo("2");
    assertThat(m2.get("3")).isEqualTo("5");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 14 with RTransaction

use of org.redisson.api.RTransaction in project redisson by redisson.

the class RedissonTransactionalLocalCachedMapTest method testRollback.

@Test
public void testRollback() {
    RLocalCachedMap<String, String> m1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m1.put("1", "2");
    m1.put("3", "4");
    RLocalCachedMap<String, String> m2 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults());
    m2.get("1");
    m2.get("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = transaction.getLocalCachedMap(m1);
    assertThat(map.get("1")).isEqualTo("2");
    assertThat(map.remove("3")).isEqualTo("4");
    assertThat(m1.get("3")).isEqualTo("4");
    transaction.rollback();
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    assertThat(m1.get("1")).isEqualTo("2");
    assertThat(m1.get("3")).isEqualTo("4");
    assertThat(m2.get("1")).isEqualTo("2");
    assertThat(m2.get("3")).isEqualTo("4");
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 15 with RTransaction

use of org.redisson.api.RTransaction in project redisson by redisson.

the class RedissonTransactionalMapCacheTest method testPutIfAbsentTTL.

@Test
public void testPutIfAbsentTTL() throws InterruptedException {
    RMapCache<Object, Object> m = redisson.getMapCache("test");
    m.put("1", "2");
    m.put("3", "4");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMapCache<Object, Object> map = transaction.getMapCache("test");
    assertThat(map.putIfAbsent("3", "2", 1, TimeUnit.SECONDS)).isEqualTo("4");
    assertThat(map.putIfAbsent("5", "6", 3, TimeUnit.SECONDS)).isNull();
    assertThat(map.putIfAbsent("5", "7", 1, TimeUnit.SECONDS)).isEqualTo("6");
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.size()).isEqualTo(2);
    transaction.commit();
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.get("5")).isEqualTo("6");
    Thread.sleep(1500);
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.get("5")).isEqualTo("6");
    Thread.sleep(1500);
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.get("5")).isNull();
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

RTransaction (org.redisson.api.RTransaction)49 Test (org.junit.jupiter.api.Test)38 BaseTest (org.redisson.BaseTest)37 Transactional (org.springframework.transaction.annotation.Transactional)9 HashSet (java.util.HashSet)5 RBuckets (org.redisson.api.RBuckets)3 LinkedHashMap (java.util.LinkedHashMap)2 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 TransactionOptions (org.redisson.api.TransactionOptions)1 NoTransactionException (org.springframework.transaction.NoTransactionException)1