Search in sources :

Example 6 with RTransaction

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

the class RedissonTransactionalSetTest method testRemoveAll.

@Test
public void testRemoveAll() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = t.getSet("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 7 with RTransaction

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

the class RedissonBaseTransactionalMapTest method testPutAll.

@Test
public void testPutAll() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(t);
    Map<String, String> putMap = new HashMap<String, String>();
    putMap.put("4", "5");
    putMap.put("6", "7");
    map.putAll(putMap);
    assertThat(m.keySet()).containsOnly("1", "3");
    t.commit();
    assertThat(m.keySet()).containsOnly("1", "3", "4", "6");
}
Also used : HashMap(java.util.HashMap) RTransaction(org.redisson.api.RTransaction) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 8 with RTransaction

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

the class RedissonBaseTransactionalMapTest method testGetAll.

@Test
public void testGetAll() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(t);
    assertThat(map.getAll(new HashSet<String>(Arrays.asList("1", "3"))).values()).containsOnly("2", "4");
    t.commit();
}
Also used : RTransaction(org.redisson.api.RTransaction) HashSet(java.util.HashSet) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 9 with RTransaction

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

the class RedissonTransactionalBucketTest method testTrySet.

@Test
public void testTrySet() {
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    assertThat(bucket.trySet("0")).isFalse();
    assertThat(bucket.delete()).isTrue();
    assertThat(bucket.trySet("324")).isTrue();
    assertThat(bucket.trySet("43")).isFalse();
    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 10 with RTransaction

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

the class RedissonTransactionalBucketTest method testCompareAndSet.

@Test
public void testCompareAndSet() {
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    assertThat(bucket.compareAndSet("0", "434")).isFalse();
    assertThat(bucket.get()).isEqualTo("123");
    assertThat(bucket.compareAndSet("123", "232")).isTrue();
    assertThat(bucket.get()).isEqualTo("232");
    transaction.commit();
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    assertThat(b.get()).isEqualTo("232");
}
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