Java Code Examples for org.redisson.api.RLocalCachedMap#put()
The following examples show how to use
org.redisson.api.RLocalCachedMap#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReadAllEntrySet() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); map.put(new SimpleKey("33"), new SimpleValue("44")); map.put(new SimpleKey("5"), new SimpleValue("6")); assertThat(map.readAllEntrySet().size()).isEqualTo(3); assertThat(cache.size()).isEqualTo(3); Map<SimpleKey, SimpleValue> testMap = new HashMap<>(map); assertThat(map.readAllEntrySet()).containsOnlyElementsOf(testMap.entrySet()); RMap<SimpleKey, SimpleValue> map2 = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); assertThat(map2.readAllEntrySet()).containsOnlyElementsOf(testMap.entrySet()); }
Example 2
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testFastPutIfAbsent() throws Exception { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); SimpleKey key = new SimpleKey("1"); SimpleValue value = new SimpleValue("2"); map.put(key, value); assertThat(map.fastPutIfAbsent(key, new SimpleValue("3"))).isFalse(); assertThat(cache.size()).isEqualTo(1); assertThat(map.get(key)).isEqualTo(value); SimpleKey key1 = new SimpleKey("2"); SimpleValue value1 = new SimpleValue("4"); assertThat(map.fastPutIfAbsent(key1, value1)).isTrue(); assertThat(cache.size()).isEqualTo(2); assertThat(map.get(key1)).isEqualTo(value1); }
Example 3
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPutIfAbsent() throws Exception { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); SimpleKey key = new SimpleKey("1"); SimpleValue value = new SimpleValue("2"); map.put(key, value); Assert.assertEquals(value, map.putIfAbsent(key, new SimpleValue("3"))); Assert.assertEquals(value, map.get(key)); SimpleKey key1 = new SimpleKey("2"); SimpleValue value1 = new SimpleValue("4"); Assert.assertNull(map.putIfAbsent(key1, value1)); Assert.assertEquals(value1, map.get(key1)); assertThat(cache.size()).isEqualTo(2); }
Example 4
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testReplaceOldValueSuccess() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3")); Assert.assertTrue(res); boolean res1 = map.replace(new SimpleKey("1"), new SimpleValue("2"), new SimpleValue("3")); Assert.assertFalse(res1); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("3", val1.getValue()); assertThat(cache.size()).isEqualTo(1); }
Example 5
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testInvalidationOnUpdateNonBinaryCodec() throws InterruptedException { LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults().evictionPolicy(EvictionPolicy.LFU).cacheSize(5); RLocalCachedMap<String, String> map1 = redisson.getLocalCachedMap("test", new StringCodec(), options); Map<String, String> cache1 = map1.getCachedMap(); RLocalCachedMap<String, String> map2 = redisson.getLocalCachedMap("test", new StringCodec(), options); Map<String, String> cache2 = map2.getCachedMap(); map1.put("1", "1"); map1.put("2", "2"); assertThat(map2.get("1")).isEqualTo("1"); assertThat(map2.get("2")).isEqualTo("2"); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.put("1", "3"); map2.put("2", "4"); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(1); assertThat(cache2.size()).isEqualTo(1); }
Example 6
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testGetAllCache() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("getAll", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("1", 100); map.put("2", 200); map.put("3", 300); map.put("4", 400); assertThat(cache.size()).isEqualTo(4); Map<String, Integer> filtered = map.getAll(new HashSet<String>(Arrays.asList("2", "3", "5"))); Map<String, Integer> expectedMap = new HashMap<String, Integer>(); expectedMap.put("2", 200); expectedMap.put("3", 300); assertThat(filtered).isEqualTo(expectedMap); RMap<String, Integer> map1 = redisson.getLocalCachedMap("getAll", LocalCachedMapOptions.defaults()); Map<String, Integer> filtered1 = map1.getAll(new HashSet<String>(Arrays.asList("2", "3", "5"))); assertThat(filtered1).isEqualTo(expectedMap); }
Example 7
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testPutGetCache() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); assertThat(cache).containsValues(1, 2, 3); assertThat(map.get("12")).isEqualTo(1); assertThat(map.get("14")).isEqualTo(2); assertThat(map.get("15")).isEqualTo(3); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); assertThat(map1.get("12")).isEqualTo(1); assertThat(map1.get("14")).isEqualTo(2); assertThat(map1.get("15")).isEqualTo(3); }
Example 8
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testLFU() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LFU).cacheSize(5)); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); map.put("16", 4); map.put("17", 5); map.put("18", 6); assertThat(cache.size()).isEqualTo(5); assertThat(map.size()).isEqualTo(6); assertThat(map.keySet()).containsOnly("12", "14", "15", "16", "17", "18"); assertThat(map.values()).containsOnly(1, 2, 3, 4, 5, 6); }
Example 9
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testLRU() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.<String, Integer>defaults().evictionPolicy(EvictionPolicy.LRU).cacheSize(5)); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); map.put("14", 2); map.put("15", 3); map.put("16", 4); map.put("17", 5); map.put("18", 6); assertThat(cache.size()).isEqualTo(5); assertThat(map.size()).isEqualTo(6); assertThat(map.keySet()).containsOnly("12", "14", "15", "16", "17", "18"); assertThat(map.values()).containsOnly(1, 2, 3, 4, 5, 6); }
Example 10
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReplaceValue() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); SimpleValue res = map.replace(new SimpleKey("1"), new SimpleValue("3")); Assert.assertEquals("2", res.getValue()); assertThat(cache.size()).isEqualTo(1); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("3", val1.getValue()); }
Example 11
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAddAndGet() throws InterruptedException { RLocalCachedMap<Integer, Integer> map = redisson.getLocalCachedMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults()); Map<Integer, Integer> cache = map.getCachedMap(); map.put(1, 100); Integer res = map.addAndGet(1, 12); assertThat(cache.size()).isEqualTo(1); assertThat(res).isEqualTo(112); res = map.get(1); assertThat(res).isEqualTo(112); RMap<Integer, Double> map2 = redisson.getLocalCachedMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE), LocalCachedMapOptions.defaults()); map2.put(1, new Double(100.2)); Double res2 = map2.addAndGet(1, new Double(12.1)); assertThat(res2).isEqualTo(112.3); res2 = map2.get(1); assertThat(res2).isEqualTo(112.3); RMap<String, Integer> mapStr = redisson.getLocalCachedMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults()); assertThat(mapStr.put("1", 100)).isNull(); assertThat(mapStr.addAndGet("1", 12)).isEqualTo(112); assertThat(mapStr.get("1")).isEqualTo(112); assertThat(cache.size()).isEqualTo(1); }
Example 12
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testPutAllCache() throws InterruptedException { RLocalCachedMap<Integer, String> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); RLocalCachedMap<Integer, String> map1 = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<Integer, String> cache = map.getCachedMap(); Map<Integer, String> cache1 = map1.getCachedMap(); map.put(1, "1"); map.put(2, "2"); map.put(3, "3"); Map<Integer, String> joinMap = new HashMap<Integer, String>(); joinMap.put(4, "4"); joinMap.put(5, "5"); joinMap.put(6, "6"); map.putAll(joinMap); assertThat(cache.size()).isEqualTo(6); assertThat(cache1.size()).isEqualTo(0); assertThat(map.keySet()).containsOnly(1, 2, 3, 4, 5, 6); map1.putAll(joinMap); // waiting for cache cleanup listeners triggering Thread.sleep(500); assertThat(cache.size()).isEqualTo(3); assertThat(cache1.size()).isEqualTo(3); }
Example 13
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemoveValue() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple12", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.remove(new SimpleKey("1"), new SimpleValue("2")); Assert.assertTrue(res); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertNull(val1); Assert.assertEquals(0, map.size()); assertThat(cache.size()).isEqualTo(0); }
Example 14
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testFastRemove() throws InterruptedException, ExecutionException { RLocalCachedMap<Integer, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); map.put(1, 3); map.put(2, 4); map.put(7, 8); assertThat(map.fastRemove(1, 2)).isEqualTo(2); assertThat(map.fastRemove(2)).isEqualTo(0); assertThat(map.size()).isEqualTo(1); }
Example 15
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testLocalCacheClear() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.INVALIDATE); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache1 = map1.getCachedMap(); RLocalCachedMap<String, Integer> map2 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.clearLocalCache(); assertThat(redisson.getKeys().count()).isEqualTo(1); assertThat(cache1.size()).isZero(); assertThat(cache2.size()).isZero(); }
Example 16
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testLocalCacheState() throws InterruptedException { LocalCachedMapOptions<String, String> options = LocalCachedMapOptions.<String, String>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.INVALIDATE); RLocalCachedMap<String, String> map = redisson.getLocalCachedMap("test", options); map.put("1", "11"); map.put("2", "22"); assertThat(map.cachedKeySet()).containsExactlyInAnyOrder("1", "2"); assertThat(map.cachedValues()).containsExactlyInAnyOrder("11", "22"); assertThat(map.getCachedMap().keySet()).containsExactlyInAnyOrder("1", "2"); assertThat(map.getCachedMap().values()).containsExactlyInAnyOrder("11", "22"); }
Example 17
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testNoInvalidationOnUpdate() throws InterruptedException { LocalCachedMapOptions<String, Integer> options = LocalCachedMapOptions.<String, Integer>defaults() .evictionPolicy(EvictionPolicy.LFU) .cacheSize(5) .syncStrategy(SyncStrategy.NONE); RLocalCachedMap<String, Integer> map1 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache1 = map1.getCachedMap(); RLocalCachedMap<String, Integer> map2 = redisson.getLocalCachedMap("test", options); Map<String, Integer> cache2 = map2.getCachedMap(); map1.put("1", 1); map1.put("2", 2); assertThat(map2.get("1")).isEqualTo(1); assertThat(map2.get("2")).isEqualTo(2); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); map1.put("1", 3); map2.put("2", 4); Thread.sleep(50); assertThat(cache1.size()).isEqualTo(2); assertThat(cache2.size()).isEqualTo(2); }
Example 18
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReplaceOldValueFail() { RLocalCachedMap<SimpleKey, SimpleValue> map = redisson.getLocalCachedMap("simple", LocalCachedMapOptions.defaults()); Map<SimpleKey, SimpleValue> cache = map.getCachedMap(); map.put(new SimpleKey("1"), new SimpleValue("2")); boolean res = map.replace(new SimpleKey("1"), new SimpleValue("43"), new SimpleValue("31")); Assert.assertFalse(res); SimpleValue val1 = map.get(new SimpleKey("1")); Assert.assertEquals("2", val1.getValue()); assertThat(cache.size()).isEqualTo(1); }
Example 19
Source File: RedissonTransactionalLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@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"); }
Example 20
Source File: RedissonLocalCachedMapTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemove() { RLocalCachedMap<String, Integer> map = redisson.getLocalCachedMap("test", LocalCachedMapOptions.defaults()); Map<String, Integer> cache = map.getCachedMap(); map.put("12", 1); assertThat(cache.size()).isEqualTo(1); assertThat(map.remove("12")).isEqualTo(1); assertThat(cache.size()).isEqualTo(0); assertThat(map.remove("14")).isNull(); }