use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonMapReactiveTest method testAddAndGet.
@Test
public void testAddAndGet() throws InterruptedException {
RMapReactive<Integer, Integer> map = redisson.getMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
sync(map.put(1, 100));
Integer res = sync(map.addAndGet(1, 12));
Assertions.assertEquals(112, (int) res);
res = sync(map.get(1));
Assertions.assertEquals(112, (int) res);
RMapReactive<Integer, Double> map2 = redisson.getMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE));
sync(map2.put(1, new Double(100.2)));
Double res2 = sync(map2.addAndGet(1, new Double(12.1)));
Assertions.assertTrue(new Double(112.3).compareTo(res2) == 0);
res2 = sync(map2.get(1));
Assertions.assertTrue(new Double(112.3).compareTo(res2) == 0);
RMapReactive<String, Integer> mapStr = redisson.getMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
assertThat(sync(mapStr.put("1", 100))).isNull();
assertThat(sync(mapStr.addAndGet("1", 12))).isEqualTo(112);
assertThat(sync(mapStr.get("1"))).isEqualTo(112);
}
use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonMapRxTest method testAddAndGet.
@Test
public void testAddAndGet() throws InterruptedException {
RMapRx<Integer, Integer> map = redisson.getMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
sync(map.put(1, 100));
Integer res = sync(map.addAndGet(1, 12));
Assertions.assertEquals(112, (int) res);
res = sync(map.get(1));
Assertions.assertEquals(112, (int) res);
RMapRx<Integer, Double> map2 = redisson.getMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE));
sync(map2.put(1, new Double(100.2)));
Double res2 = sync(map2.addAndGet(1, new Double(12.1)));
Assertions.assertTrue(new Double(112.3).compareTo(res2) == 0);
res2 = sync(map2.get(1));
Assertions.assertTrue(new Double(112.3).compareTo(res2) == 0);
RMapRx<String, Integer> mapStr = redisson.getMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
assertThat(sync(mapStr.put("1", 100))).isNull();
assertThat(sync(mapStr.addAndGet("1", 12))).isEqualTo(112);
assertThat(sync(mapStr.get("1"))).isEqualTo(112);
}
Aggregations