use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testFastPut.
@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();
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonBaseTransactionalMapTest method testReplace.
@Test
public void testReplace() {
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", "10")).isEqualTo("4");
assertThat(map.replace("5", "0")).isNull();
assertThat(m.get("3")).isEqualTo("4");
assertThat(m.size()).isEqualTo(2);
transaction.commit();
assertThat(m.size()).isEqualTo(2);
assertThat(m.get("3")).isEqualTo("10");
assertThat(m.get("5")).isNull();
RTransaction transaction2 = redisson.createTransaction(TransactionOptions.defaults());
RMap<String, String> map2 = getTransactionalMap(transaction2);
assertThat(map2.replace("3", "20")).isEqualTo("10");
assertThat(map2.replace("3", "30")).isEqualTo("20");
assertThat(m.get("3")).isEqualTo("10");
assertThat(m.size()).isEqualTo(2);
transaction2.commit();
assertThat(m.get("3")).isEqualTo("30");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalSetCacheTest method testAdd.
@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();
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalSetCacheTest method testKeySet.
@Test
public void testKeySet() {
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.remove("3");
assertThat(set).containsOnly("1");
assertThat(s).containsOnly("1", "3");
}
use of org.redisson.api.RTransaction in project redisson by redisson.
the class RedissonTransactionalSetCacheTest method testRemove.
@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();
}
Aggregations