Java Code Examples for org.redisson.api.RListMultimap#replaceValues()

The following examples show how to use org.redisson.api.RListMultimap#replaceValues() . 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: ListMultimapExamples.java    From redisson-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();
    
    RListMultimap<String, Integer> multimap = redisson.getListMultimap("myMultimap");
    multimap.put("1", 1);
    multimap.put("1", 2);
    multimap.put("1", 3);
    multimap.put("2", 5);
    multimap.put("2", 6);
    multimap.put("4", 7);
    
    RList<Integer> values1 = multimap.get("1");
    RList<Integer> values2 = multimap.get("2");
    
    boolean hasEntry = multimap.containsEntry("1", 3);
    Collection<Entry<String, Integer>> entries = multimap.entries();
    Collection<Integer> values = multimap.values();
    
    boolean isRemoved = multimap.remove("1", 3);
    List<Integer> removedValues = multimap.removeAll("1");
    
    Collection<? extends Integer> newValues = Arrays.asList(5, 6, 7, 8, 9);
    boolean isNewKey = multimap.putAll("5", newValues);
    
    List<Integer> oldValues = multimap.replaceValues("2", newValues);
    List<Integer> allValues = multimap.getAll("2");
    
    long keysRemoved = multimap.fastRemove("2", "32");
    
    redisson.shutdown();
}
 
Example 2
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceValues() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    List<SimpleValue> values = Arrays.asList(new SimpleValue("11"), new SimpleValue("12"), new SimpleValue("12"));
    List<SimpleValue> oldValues = map.replaceValues(new SimpleKey("0"), values);
    assertThat(oldValues).containsExactly(new SimpleValue("1"));

    List<SimpleValue> allValues = map.getAll(new SimpleKey("0"));
    assertThat(allValues).containsExactlyElementsOf(values);
}