Search in sources :

Example 1 with RTransaction

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

the class RedissonTransactionalBucketsTest method testGet.

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

Example 2 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testPutAll.

@Test
public void testPutAll() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = t.getSetCache("test");
    Set<String> putSet = new HashSet<String>();
    putSet.add("4");
    putSet.add("6");
    set.addAll(putSet);
    assertThat(s).containsOnly("1", "3");
    assertThat(set).containsOnly("1", "3", "4", "6");
    t.commit();
    assertThat(s).containsOnly("1", "3", "4", "6");
}
Also used : RTransaction(org.redisson.api.RTransaction) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 3 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testAddTTL.

@Test
public void testAddTTL() throws InterruptedException {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = transaction.getSetCache("test");
    assertThat(set.add("4", 2, TimeUnit.SECONDS)).isTrue();
    assertThat(set.add("3")).isFalse();
    assertThat(set.contains("4")).isTrue();
    assertThat(s.contains("4")).isFalse();
    transaction.commit();
    assertThat(s.size()).isEqualTo(3);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isTrue();
    assertThat(s.contains("4")).isTrue();
    Thread.sleep(2000);
    assertThat(s.contains("4")).isFalse();
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 4 with RTransaction

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

the class RedissonTransactionalSetCacheTest method testRemoveAll.

@Test
public void testRemoveAll() {
    RSetCache<String> s = redisson.getSetCache("test");
    s.add("1");
    s.add("3");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSetCache<String> set = t.getSetCache("test");
    Set<String> putSet = new HashSet<String>();
    putSet.add("4");
    putSet.add("3");
    set.removeAll(putSet);
    assertThat(s).containsOnly("1", "3");
    assertThat(set).containsOnly("1");
    t.commit();
    assertThat(s).containsOnly("1");
}
Also used : RTransaction(org.redisson.api.RTransaction) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

Example 5 with RTransaction

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

the class RedissonTransactionalSetTest method testRemove.

@Test
public void testRemove() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = transaction.getSet("test");
    assertThat(set.contains("1")).isTrue();
    assertThat(set.remove("3")).isTrue();
    assertThat(set.remove("3")).isFalse();
    assertThat(set.remove("3")).isFalse();
    assertThat(s.contains("3")).isTrue();
    transaction.commit();
    assertThat(s.size()).isEqualTo(1);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isFalse();
}
Also used : RTransaction(org.redisson.api.RTransaction) Test(org.junit.jupiter.api.Test) BaseTest(org.redisson.BaseTest)

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