Search in sources :

Example 1 with RTransactionReactive

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

the class RedissonTransactionalBucketReactiveTest method testGetAndSet.

@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");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 2 with RTransactionReactive

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

the class RedissonTransactionalBucketReactiveTest method testGetAndRemove.

@Test
public void testGetAndRemove() {
    RBucketReactive<String> m = redisson.getBucket("test");
    sync(m.set("123"));
    RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBucketReactive<String> set = transaction.getBucket("test");
    assertThat(sync(set.get())).isEqualTo("123");
    assertThat(sync(set.size())).isEqualTo(6);
    assertThat(sync(set.getAndDelete())).isEqualTo("123");
    assertThat(sync(set.size())).isEqualTo(0);
    assertThat(sync(set.get())).isNull();
    assertThat(sync(set.getAndDelete())).isNull();
    sync(transaction.commit());
    assertThat(sync(redisson.getKeys().count())).isEqualTo(0);
    assertThat(sync(m.get())).isNull();
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 3 with RTransactionReactive

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

the class RedissonTransactionalBucketReactiveTest method testCompareAndSet.

@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");
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Example 4 with RTransactionReactive

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

the class ReactiveRedissonTransactionManager method doBegin.

@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();
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) TransactionOptions(org.redisson.api.TransactionOptions)

Example 5 with RTransactionReactive

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

the class RedissonTransactionalBucketReactiveTest method testLock.

@Test
public void testLock() {
    redisson.getBucket("e:1", LongCodec.INSTANCE).set(1L).block();
    redisson.getBucket("e:2", LongCodec.INSTANCE).set(1L).block();
    for (int j = 0; j < 10; j++) {
        RTransactionReactive transaction = redisson.createTransaction(TransactionOptions.defaults().timeout(30, TimeUnit.SECONDS));
        RBucketReactive<Long> e1 = transaction.getBucket("e:1", LongCodec.INSTANCE);
        RBucketReactive<Long> e2 = transaction.getBucket("e:2", LongCodec.INSTANCE);
        e1.get().map(i -> i + 1).flatMap(e1::set).block();
        e2.get().map(i -> i - 1).flatMap(e2::set).block();
        transaction.commit().block();
    }
    assertThat(redisson.getBucket("e:1", LongCodec.INSTANCE).get().block()).isEqualTo(11L);
    assertThat(redisson.getBucket("e:2", LongCodec.INSTANCE).get().block()).isEqualTo(-9L);
}
Also used : RTransactionReactive(org.redisson.api.RTransactionReactive) Test(org.junit.jupiter.api.Test) BaseReactiveTest(org.redisson.BaseReactiveTest)

Aggregations

RTransactionReactive (org.redisson.api.RTransactionReactive)9 Test (org.junit.jupiter.api.Test)8 BaseReactiveTest (org.redisson.BaseReactiveTest)8 TransactionOptions (org.redisson.api.TransactionOptions)1