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");
}
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");
}
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");
}
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");
}
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();
}
Aggregations