Search in sources :

Example 11 with CompositeCodec

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);
}
Also used : CompositeCodec(org.redisson.codec.CompositeCodec) Test(org.junit.jupiter.api.Test)

Example 12 with CompositeCodec

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);
}
Also used : CompositeCodec(org.redisson.codec.CompositeCodec) Test(org.junit.jupiter.api.Test)

Aggregations

CompositeCodec (org.redisson.codec.CompositeCodec)12 Test (org.junit.jupiter.api.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 RedissonMap (org.redisson.RedissonMap)1 RemoteInvocationOptions (org.redisson.api.RemoteInvocationOptions)1 StreamMessageId (org.redisson.api.StreamMessageId)1 MessageListener (org.redisson.api.listener.MessageListener)1 Codec (org.redisson.client.codec.Codec)1 StringCodec (org.redisson.client.codec.StringCodec)1 RedisCommand (org.redisson.client.protocol.RedisCommand)1 BucketsDecoder (org.redisson.connection.decoder.BucketsDecoder)1 MapGetAllDecoder (org.redisson.connection.decoder.MapGetAllDecoder)1 MapSession (org.springframework.session.MapSession)1