Java Code Examples for org.redisson.api.RMap#getAll()

The following examples show how to use org.redisson.api.RMap#getAll() . 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: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllWithStringKeys() {
    RMap<String, Integer> map = getMap("getAllStrings");
    map.put("A", 100);
    map.put("B", 200);
    map.put("C", 300);
    map.put("D", 400);

    Map<String, Integer> filtered = map.getAll(new HashSet<String>(Arrays.asList("B", "C", "E")));

    Map<String, Integer> expectedMap = new HashMap<String, Integer>();
    expectedMap.put("B", 200);
    expectedMap.put("C", 300);
    assertThat(filtered).isEqualTo(expectedMap);
    
    destroy(map);
}
 
Example 2
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllBig() {
    Map<Integer, String> joinMap = new HashMap<Integer, String>();
    for (int i = 0; i < 10000; i++) {
        joinMap.put(i, "" + i);
    }
    
    RMap<Integer, String> map = getMap("simple");
    map.putAll(joinMap);
    
    Map<Integer, String> s = map.getAll(joinMap.keySet());
    assertThat(s).isEqualTo(joinMap);
    
    assertThat(map.size()).isEqualTo(joinMap.size());
    destroy(map);
}
 
Example 3
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAll() {
    RMap<Integer, Integer> map = getMap("getAll");
    map.put(1, 100);
    map.put(2, 200);
    map.put(3, 300);
    map.put(4, 400);

    Map<Integer, Integer> filtered = map.getAll(new HashSet<Integer>(Arrays.asList(2, 3, 5)));

    Map<Integer, Integer> expectedMap = new HashMap<Integer, Integer>();
    expectedMap.put(2, 200);
    expectedMap.put(3, 300);
    assertThat(filtered).isEqualTo(expectedMap);
    destroy(map);
}
 
Example 4
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllOrder() {
    RMap<Integer, Integer> map = getMap("getAll");
    map.put(1, 100);
    map.put(2, 200);
    map.put(3, 300);
    map.put(4, 400);
    map.put(5, 500);
    map.put(6, 600);
    map.put(7, 700);
    map.put(8, 800);

    Map<Integer, Integer> filtered = map.getAll(new HashSet<Integer>(Arrays.asList(2, 3, 5, 1, 7, 8)));

    Map<Integer, Integer> expectedMap = new LinkedHashMap<Integer, Integer>();
    expectedMap.put(1, 100);
    expectedMap.put(2, 200);
    expectedMap.put(3, 300);
    expectedMap.put(5, 500);
    expectedMap.put(7, 700);
    expectedMap.put(8, 800);
    
    assertThat(filtered.entrySet()).containsExactlyElementsOf(expectedMap.entrySet());
    destroy(map);
}
 
Example 5
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllOrderPartially() {
    RMap<Integer, Integer> map = getMap("getAll");
    map.put(1, 100);
    map.put(2, 200);
    map.put(3, 300);
    map.put(4, 400);
    RMap<Integer, Integer> map2 = getMap("getAll");
    map2.put(5, 500);
    map2.put(6, 600);
    map2.put(7, 700);
    map2.put(8, 800);

    Map<Integer, Integer> filtered = map.getAll(new HashSet<Integer>(Arrays.asList(2, 3, 5, 1, 7, 8)));

    Map<Integer, Integer> expectedMap = new LinkedHashMap<Integer, Integer>();
    expectedMap.put(1, 100);
    expectedMap.put(2, 200);
    expectedMap.put(3, 300);
    expectedMap.put(5, 500);
    expectedMap.put(7, 700);
    expectedMap.put(8, 800);
    
    assertThat(filtered.entrySet()).containsExactlyElementsOf(expectedMap.entrySet());
    destroy(map);
}
 
Example 6
Source File: BaseMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapLoaderGet() {
    Map<String, String> cache = new HashMap<String, String>();
    cache.put("1", "11");
    cache.put("2", "22");
    cache.put("3", "33");
    
    RMap<String, String> map = getLoaderTestMap("test", cache);
    
    assertThat(map.size()).isEqualTo(0);
    assertThat(map.get("1")).isEqualTo("11");
    assertThat(map.size()).isEqualTo(1);
    assertThat(map.get("0")).isNull();
    map.put("0", "00");
    assertThat(map.get("0")).isEqualTo("00");
    assertThat(map.size()).isEqualTo(2);
    
    Map<String, String> s = map.getAll(new HashSet<>(Arrays.asList("1", "2", "9", "3")));
    Map<String, String> expectedMap = new HashMap<>();
    expectedMap.put("1", "11");
    expectedMap.put("2", "22");
    expectedMap.put("3", "33");
    assertThat(s).isEqualTo(expectedMap);
    assertThat(map.size()).isEqualTo(4);
    destroy(map);
}
 
Example 7
Source File: RedissonLocalCachedMapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: MapExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RMap<String, Integer> map =  redisson.getMap("myMap");
    map.put("a", 1);
    map.put("b", 2);
    map.put("c", 3);
    
    boolean contains = map.containsKey("a");
    
    Integer value = map.get("c");
    Integer updatedValue = map.addAndGet("a", 32);
    
    Integer valueSize = map.valueSize("c");
    
    Set<String> keys = new HashSet<String>();
    keys.add("a");
    keys.add("b");
    keys.add("c");
    Map<String, Integer> mapSlice = map.getAll(keys);
    
    // use read* methods to fetch all objects
    Set<String> allKeys = map.readAllKeySet();
    Collection<Integer> allValues = map.readAllValues();
    Set<Entry<String, Integer>> allEntries = map.readAllEntrySet();
    
    // use fast* methods when previous value is not required
    boolean isNewKey = map.fastPut("a", 100);
    boolean isNewKeyPut = map.fastPutIfAbsent("d", 33);
    long removedAmount = map.fastRemove("b");
    
    redisson.shutdown();
}