org.redisson.api.TransactionOptions Java Examples

The following examples show how to use org.redisson.api.TransactionOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollback() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.get("1")).isEqualTo("2");
    assertThat(map.remove("3")).isEqualTo("4");
    
    assertThat(m.get("3")).isEqualTo("4");
    
    transaction.rollback();
    
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.get("3")).isEqualTo("4");
}
 
Example #2
Source File: RedissonTransactionalLocalCachedMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPut() throws InterruptedException {
    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.put("3", "5")).isEqualTo("4");
    assertThat(map.get("3")).isEqualTo("5");
    
    assertThat(m1.get("3")).isEqualTo("4");
    assertThat(m2.get("3")).isEqualTo("4");
    
    transaction.commit();
    
    assertThat(m1.get("3")).isEqualTo("5");
    assertThat(m2.get("3")).isEqualTo("5");
}
 
Example #3
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test(expected = TransactionTimeoutException.class)
public void testParallel(){
    RMap<Integer, String> m = redisson.getMap("test");
    m.put(1, "test");
    
    RTransaction transaction1 = redisson.createTransaction(TransactionOptions.defaults().timeout(10, TimeUnit.SECONDS));
    RMap<Integer, String> map1 = transaction1.getMap("put_test");
    map1.remove(1);

    RTransaction transaction2 = redisson.createTransaction(TransactionOptions.defaults());
    RMap<Integer, String> map2 = transaction2.getMap("put_test");
    map2.put(1,"aryan");
    
    try {
        transaction2.commit();
        Assert.fail();
    } catch (TransactionTimeoutException e) {
        // skip
    }
    
    transaction1.commit();
    assertThat(m.size()).isZero();
}
 
Example #4
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testFastPut() throws InterruptedException {
    ExecutorService executor = Executors.newFixedThreadPool(2000);
    for (int i = 0; i < 2000; i++) {
        executor.submit(() -> {
            for (int j = 0; j < 100; j++) {
                RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
                RMap<String, String> map = getTransactionalMap(t);
                map.fastPut("1", "1");
                t.commit();
            }
        });
    }
    
    executor.shutdown();
    assertThat(executor.awaitTermination(2, TimeUnit.MINUTES)).isTrue();
}
 
Example #5
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #6
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplace2() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.replace("3", "4", "10")).isTrue();
    assertThat(map.replace("1", "1", "3")).isFalse();
    assertThat(map.replace("3", "10", "11")).isTrue();
    
    assertThat(m.get("3")).isEqualTo("4");
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.size()).isEqualTo(2);
    
    transaction.commit();
    
    assertThat(m.size()).isEqualTo(2);
    assertThat(m.get("3")).isEqualTo("11");
    assertThat(m.get("1")).isEqualTo("2");
}
 
Example #7
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutIfAbsent() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.putIfAbsent("3", "2")).isEqualTo("4");
    assertThat(map.putIfAbsent("5", "6")).isNull();
    assertThat(map.putIfAbsent("5", "7")).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");
}
 
Example #8
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutIfAbsentRemove() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.putIfAbsent("3", "2")).isEqualTo("4");
    assertThat(map.putIfAbsent("5", "6")).isNull();
    assertThat(map.putIfAbsent("5", "7")).isEqualTo("6");
    assertThat(map.remove("5")).isEqualTo("6");
    assertThat(map.putIfAbsent("5", "8")).isNull();
    
    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("8");
}
 
Example #9
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemove() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.get("1")).isEqualTo("2");
    assertThat(map.remove("3")).isEqualTo("4");
    assertThat(map.remove("3")).isNull();
    assertThat(map.remove("3")).isNull();
    
    assertThat(m.get("3")).isEqualTo("4");
    
    transaction.commit();
    
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.get("3")).isNull();
}
 
Example #10
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPut() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    assertThat(map.put("3", "5")).isEqualTo("4");
    assertThat(map.get("3")).isEqualTo("5");
    
    assertThat(m.get("3")).isEqualTo("4");
    
    transaction.commit();
    
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.get("3")).isEqualTo("5");
}
 
Example #11
Source File: RedissonBaseTransactionalMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutRemove() {
    RMap<String, String> m = getMap();
    m.put("1", "2");
    m.put("3", "4");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RMap<String, String> map = getTransactionalMap(transaction);
    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(m.get("3")).isEqualTo("4");
    
    transaction.commit();
    
    assertThat(m.get("1")).isEqualTo("2");
    assertThat(m.get("3")).isEqualTo("5");
}
 
Example #12
Source File: RedissonTransactionalLocalCachedMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #13
Source File: RedissonTransactionalBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws InterruptedException {
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(3, TimeUnit.SECONDS));
    RBucket<String> bucket = transaction.getBucket("test");
    bucket.set("234");
    
    Thread.sleep(4000);
    
    try {
        transaction.commit();
        Assert.fail();
    } catch (TransactionException e) {
        // skip
    }
    
    Thread.sleep(1000);
    
    assertThat(b.get()).isEqualTo("123");
}
 
Example #14
Source File: RedissonTransactionalBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #15
Source File: RedissonTransactionalBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #16
Source File: RedissonTransactionalBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #17
Source File: RedissonTransactionalBucketTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollback() {
    RBucket<Object> b = redisson.getBucket("test");
    b.set("1234");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<Object> bucket = transaction.getBucket("test");
    assertThat(bucket.get()).isEqualTo("1234");
    assertThat(bucket.getAndDelete()).isEqualTo("1234");
    
    assertThat(b.get()).isEqualTo("1234");
    
    transaction.rollback();
    
    assertThat(redisson.getKeys().count()).isEqualTo(1);
    
    assertThat(b.get()).isEqualTo("1234");
}
 
Example #18
Source File: RedissonTransactionalBucketReactiveTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws InterruptedException {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(3, TimeUnit.SECONDS));
    RBucketReactive<String> bucket = transaction.getBucket("test");
    sync(bucket.set("234"));
    
    Thread.sleep(3000);
    
    try {
        sync(transaction.commit());
        Assert.fail();
    } catch (TransactionException e) {
        // skip
    }
    
    Thread.sleep(1000);
    
    assertThat(sync(b.get())).isEqualTo("123");
}
 
Example #19
Source File: RedissonTransactionalBucketReactiveTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAndSet() {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.getAndSet("0"))).isEqualTo("123");
    assertThat(sync(bucket.get())).isEqualTo("0");
    assertThat(sync(bucket.getAndSet("324"))).isEqualTo("0");
    
    sync(transaction.commit());
    
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("324");
}
 
Example #20
Source File: RedissonTransactionalBucketReactiveTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testCompareAndSet() {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.compareAndSet("0", "434"))).isFalse();
    assertThat(sync(bucket.get())).isEqualTo("123");
    assertThat(sync(bucket.compareAndSet("123", "232"))).isTrue();
    assertThat(sync(bucket.get())).isEqualTo("232");
    
    sync(transaction.commit());
    
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("232");
}
 
Example #21
Source File: RedissonTransactionalBucketReactiveTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testTrySet() {
    RBucketReactive<String> b = redisson.getBucket("test");
    sync(b.set("123"));
    
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.trySet("0"))).isFalse();
    assertThat(sync(bucket.delete())).isTrue();
    assertThat(sync(bucket.trySet("324"))).isTrue();
    assertThat(sync(bucket.trySet("43"))).isFalse();
    
    sync(transaction.commit());
    
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    assertThat(sync(b.get())).isEqualTo("324");
}
 
Example #22
Source File: RedissonTransactionalBucketReactiveTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRollback() {
    RBucketReactive<Object> b = redisson.getBucket("test");
    sync(b.set("1234"));
    
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<Object> bucket = transaction.getBucket("test");
    assertThat(sync(bucket.get())).isEqualTo("1234");
    assertThat(sync(bucket.getAndDelete())).isEqualTo("1234");
    
    assertThat(sync(b.get())).isEqualTo("1234");
    
    sync(transaction.rollback());
    
    assertThat(sync(redisson.getKeys().count())).isEqualTo(1);
    
    assertThat(sync(b.get())).isEqualTo("1234");
}
 
Example #23
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemove() {
    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.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();
}
 
Example #24
Source File: TransactionExamples.java    From redisson-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RBucket<String> b = redisson.getBucket("test");
    b.set("123");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucket<String> bucket = transaction.getBucket("test");
    bucket.set("234");
    
    RMap<String, String> map = transaction.getMap("myMap");
    map.put("1", "2");
    
    transaction.commit();
}
 
Example #25
Source File: RedissonTransactionManager.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #26
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
protected Mono<Void> doBegin(TransactionSynchronizationManager synchronizationManager, Object transaction, TransactionDefinition definition) throws TransactionException {
    ReactiveRedissonTransactionObject tObject = (ReactiveRedissonTransactionObject) transaction;

    TransactionOptions options = TransactionOptions.defaults();
    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT) {
        options.timeout(definition.getTimeout(), TimeUnit.SECONDS);
    }

    RTransactionReactive trans = redissonClient.createTransaction(options);
    ReactiveRedissonResourceHolder holder = new ReactiveRedissonResourceHolder();
    holder.setTransaction(trans);
    tObject.setResourceHolder(holder);
    synchronizationManager.bindResource(redissonClient, holder);

    return Mono.empty();
}
 
Example #27
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #28
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #29
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdd() {
    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")).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();
}
 
Example #30
Source File: RedissonTransactionalSetCacheTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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();
}