org.redisson.api.RSetMultimap Java Examples

The following examples show how to use org.redisson.api.RSetMultimap. 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: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRenamenx() {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");

    RSetMultimap<String, String> map2 = redisson.getSetMultimap("simple2");
    map2.put("4", "5");

    assertThat(map.renamenx("simple2")).isFalse();
    assertThat(map.size()).isEqualTo(2);
    assertThat(map.get("1")).containsOnly("2");
    assertThat(map.get("2")).containsOnly("3");
    assertThat(map2.get("4")).containsOnly("5");

    assertThat(map.renamenx("simple3")).isTrue();

    RSetMultimap<String, String> map3 = redisson.getSetMultimap("simple");
    assertThat(map3.isExists()).isFalse();
    assertThat(map3.isEmpty()).isTrue();

    RSetMultimap<String, String> map4 = redisson.getSetMultimap("simple3");
    assertThat(map4.size()).isEqualTo(2);
    assertThat(map4.get("1")).containsOnly("2");
    assertThat(map4.get("2")).containsOnly("3");
}
 
Example #2
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPut() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.size()).isEqualTo(4);

    Set<SimpleValue> s1 = map.get(new SimpleKey("0"));
    assertThat(s1).containsOnly(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"));
    Set<SimpleValue> allValues = map.getAll(new SimpleKey("0"));
    assertThat(allValues).containsOnly(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"));

    Set<SimpleValue> s2 = map.get(new SimpleKey("3"));
    assertThat(s2).containsOnly(new SimpleValue("4"));
}
 
Example #3
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testKeySize() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("1"), new SimpleValue("3"));

    assertThat(map.keySize()).isEqualTo(2);
    assertThat(map.keySet().size()).isEqualTo(2);

    map.fastRemove(new SimpleKey("0"));

    Set<SimpleValue> s = map.get(new SimpleKey("0"));
    assertThat(s).isEmpty();
    assertThat(map.keySize()).isEqualTo(1);
}
 
Example #4
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRemoveAll() {
    RSetMultimap<String, Integer> multimap1 = redisson.getSetMultimap("myMultimap1");
    Set<Integer> one = multimap1.get("1");
    Set<Integer> two = multimap1.get("2");
    Set<Integer> four = multimap1.get("4");
    one.add(1);
    one.add(2);
    one.add(3);
    two.add(5);
    two.add(6);
    four.add(7);
    
    assertThat(one.removeAll(Arrays.asList(1, 2, 3))).isTrue();
    assertThat(two.removeAll(Arrays.asList(5, 6))).isTrue();
    assertThat(four.removeAll(Arrays.asList(7))).isTrue();
    assertThat(four.removeAll(Arrays.asList(9))).isFalse();
    
    assertThat(multimap1.keySet()).isEmpty();
    assertThat(multimap1.keySize()).isEqualTo(0);
}
 
Example #5
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRemove() {
    RSetMultimap<String, Integer> multimap1 = redisson.getSetMultimap("myMultimap1");
    Set<Integer> one = multimap1.get("1");
    Set<Integer> two = multimap1.get("2");
    Set<Integer> four = multimap1.get("4");
    one.add(1);
    one.add(2);
    one.add(3);
    two.add(5);
    two.add(6);
    four.add(7);
    
    assertThat(one.remove(1)).isTrue();
    assertThat(one.remove(2)).isTrue();
    assertThat(two.remove(5)).isTrue();
    assertThat(four.remove(7)).isTrue();
    
    assertThat(multimap1.keySet()).containsOnly("1", "2");
    assertThat(multimap1.keySize()).isEqualTo(2);
    assertThat(multimap1.get("1")).containsOnly(3);
    assertThat(multimap1.get("2")).containsOnly(6);
}
 
Example #6
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAddAll() {
    RSetMultimap<String, Integer> multimap1 = redisson.getSetMultimap("myMultimap1");
    Set<Integer> one = multimap1.get("1");
    Set<Integer> two = multimap1.get("2");
    Set<Integer> four = multimap1.get("4");
    one.addAll(Arrays.asList(1, 2, 3));
    two.addAll(Arrays.asList(5, 6));
    four.addAll(Arrays.asList(7));
    
    assertThat(multimap1.keySet()).containsOnly("1", "2", "4");
    assertThat(multimap1.keySize()).isEqualTo(3);
    assertThat(multimap1.get("1")).containsOnly(1, 2, 3);
    assertThat(multimap1.get("2")).containsOnly(5, 6);
    assertThat(multimap1.get("4")).containsOnly(7);
}
 
Example #7
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAdd() {
    RSetMultimap<String, Integer> multimap1 = redisson.getSetMultimap("myMultimap1");
    Set<Integer> one = multimap1.get("1");
    Set<Integer> two = multimap1.get("2");
    Set<Integer> four = multimap1.get("4");
    one.add(1);
    one.add(2);
    one.add(3);
    two.add(5);
    two.add(6);
    four.add(7);
    
    assertThat(multimap1.keySet()).containsOnly("1", "2", "4");
    assertThat(multimap1.keySize()).isEqualTo(3);
    assertThat(multimap1.get("1")).containsOnly(1, 2, 3);
    assertThat(multimap1.get("2")).containsOnly(5, 6);
    assertThat(multimap1.get("4")).containsOnly(7);
}
 
Example #8
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");
    assertThat(map.delete()).isTrue();
    
    RSetMultimap<String, String> map2 = redisson.getSetMultimap("simple1");
    assertThat(map2.delete()).isFalse();

    RSetMultimap<String, String> multiset = redisson.getSetMultimap( "test" );
    multiset.put("1", "01");
    multiset.put("1", "02");
    multiset.put("1", "03");
    RSet<String> set = multiset.get( "1" );

    set.delete();
    assertThat(multiset.size()).isZero();
    assertThat(multiset.get("1").size()).isZero();
}
 
Example #9
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRename() {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");
    map.rename("simple2");

    RSetMultimap<String, String> map2 = redisson.getSetMultimap("simple2");
    assertThat(map2.size()).isEqualTo(2);
    assertThat(map2.get("1")).containsOnly("2");
    assertThat(map2.get("2")).containsOnly("3");

    RSetMultimap<String, String> map3 = redisson.getSetMultimap("simple");
    assertThat(map3.isExists()).isFalse();
    assertThat(map3.isEmpty()).isTrue();
}
 
Example #10
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpire() throws InterruptedException {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");

    map.expire(100, TimeUnit.MILLISECONDS);

    Thread.sleep(500);

    assertThat(map.size()).isZero();
}
 
Example #11
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceValues() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("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"));
    Set<SimpleValue> oldValues = map.replaceValues(new SimpleKey("0"), values);
    assertThat(oldValues).containsOnly(new SimpleValue("1"));

    Set<SimpleValue> allValues = map.getAll(new SimpleKey("0"));
    assertThat(allValues).containsOnlyElementsOf(values);
}
 
Example #12
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpireAt() throws InterruptedException {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");

    map.expireAt(System.currentTimeMillis() + 100);

    Thread.sleep(500);

    assertThat(map.size()).isZero();
}
 
Example #13
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearExpire() throws InterruptedException {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");

    map.expireAt(System.currentTimeMillis() + 100);

    map.clearExpire();

    Thread.sleep(500);

    assertThat(map.size()).isEqualTo(2);
}
 
Example #14
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntrySet() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.entries().size()).isEqualTo(2);
    Map<SimpleKey, SimpleValue> testMap = new HashMap<SimpleKey, SimpleValue>();
    testMap.put(new SimpleKey("0"), new SimpleValue("1"));
    testMap.put(new SimpleKey("3"), new SimpleValue("4"));
    assertThat(map.entries()).containsOnlyElementsOf(testMap.entrySet());
}
 
Example #15
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));

    Set<SimpleValue> values = map.removeAll(new SimpleKey("0"));
    assertThat(values).containsOnly(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"));
    assertThat(map.size()).isZero();

    Set<SimpleValue> values2 = map.removeAll(new SimpleKey("0"));
    assertThat(values2).isEmpty();
}
 
Example #16
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testValues() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.values()).containsOnly(new SimpleValue("1"), new SimpleValue("4"));
}
 
Example #17
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeySet() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.keySet()).containsOnly(new SimpleKey("0"), new SimpleKey("3"));
    assertThat(map.keySet().size()).isEqualTo(2);
}
 
Example #18
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutAll() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    List<SimpleValue> values = Arrays.asList(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"));
    assertThat(map.putAll(new SimpleKey("0"), values)).isTrue();
    assertThat(map.putAll(new SimpleKey("0"), Arrays.asList(new SimpleValue("1")))).isFalse();

    assertThat(map.get(new SimpleKey("0"))).containsOnlyElementsOf(values);
}
 
Example #19
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemove() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));

    assertThat(map.remove(new SimpleKey("0"), new SimpleValue("2"))).isTrue();
    assertThat(map.remove(new SimpleKey("0"), new SimpleValue("5"))).isFalse();
    assertThat(map.get(new SimpleKey("0")).size()).isEqualTo(2);
    assertThat(map.getAll(new SimpleKey("0")).size()).isEqualTo(2);
}
 
Example #20
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsEntry() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));

    assertThat(map.containsEntry(new SimpleKey("0"), new SimpleValue("1"))).isTrue();
    assertThat(map.containsEntry(new SimpleKey("0"), new SimpleValue("2"))).isFalse();
}
 
Example #21
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsValue() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));

    assertThat(map.containsValue(new SimpleValue("1"))).isTrue();
    assertThat(map.containsValue(new SimpleValue("0"))).isFalse();
}
 
Example #22
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsKey() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    assertThat(map.containsKey(new SimpleKey("0"))).isTrue();
    assertThat(map.containsKey(new SimpleKey("1"))).isFalse();
}
 
Example #23
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFastRemove() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    assertThat(map.put(new SimpleKey("0"), new SimpleValue("1"))).isTrue();
    assertThat(map.put(new SimpleKey("0"), new SimpleValue("2"))).isTrue();
    assertThat(map.put(new SimpleKey("0"), new SimpleValue("2"))).isFalse();
    assertThat(map.put(new SimpleKey("0"), new SimpleValue("3"))).isTrue();

    long removed = map.fastRemove(new SimpleKey("0"), new SimpleKey("1"));
    assertThat(removed).isEqualTo(1);
    assertThat(map.size()).isZero();
}
 
Example #24
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAllFromCollection() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));

    Collection<SimpleValue> values = Arrays.asList(new SimpleValue("1"), new SimpleValue("2"));
    assertThat(map.get(new SimpleKey("0")).removeAll(values)).isTrue();
    assertThat(map.get(new SimpleKey("0")).size()).isEqualTo(1);
    assertThat(map.get(new SimpleKey("0")).removeAll(Arrays.asList(new SimpleValue("3")))).isTrue();
    assertThat(map.get(new SimpleKey("0")).size()).isZero();
    assertThat(map.get(new SimpleKey("0")).removeAll(Arrays.asList(new SimpleValue("3")))).isFalse();
}
 
Example #25
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSize() {
    RSetMultimap<SimpleKey, SimpleValue> map = redisson.getSetMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));

    assertThat(map.size()).isEqualTo(2);

    map.fastRemove(new SimpleKey("0"));

    Set<SimpleValue> s = map.get(new SimpleKey("0"));
    assertThat(s).isEmpty();
    assertThat(map.size()).isEqualTo(0);
}
 
Example #26
Source File: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll2() {
    RSetMultimap<String, Long> testMap = redisson.getSetMultimap( "test-2" );
    testMap.clear();
    testMap.put( "t1", 1L );
    testMap.put( "t1", 2L );
    testMap.put( "t1", 3L );
    RSet<Long> set = testMap.get( "t1" );
    set.removeAll( Arrays.asList( 1L, 2L ) );
    assertThat(testMap.size()).isOne();
    assertThat(testMap.get( "t1" ).size()).isEqualTo(1);
    testMap.clear();
    assertThat(testMap.size()).isZero();
    assertThat(testMap.get( "t1" ).size()).isZero();
}
 
Example #27
Source File: SetMultimapExamples.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();
    
    RSetMultimap<String, Integer> multimap = redisson.getSetMultimap("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);
    
    RSet<Integer> values1 = multimap.get("1");
    RSet<Integer> values2 = multimap.get("2");
    
    boolean hasEntry = multimap.containsEntry("1", 3);
    Set<Entry<String, Integer>> entries = multimap.entries();
    Collection<Integer> values = multimap.values();
    
    boolean isRemoved = multimap.remove("1", 3);
    Set<Integer> removedValues = multimap.removeAll("1");
    
    Collection<? extends Integer> newValues = Arrays.asList(5, 6, 7, 8, 9);
    boolean isNewKey = multimap.putAll("5", newValues);
    
    Set<Integer> oldValues = multimap.replaceValues("2", newValues);
    Set<Integer> allValues = multimap.getAll("2");
    
    redisson.shutdown();
}
 
Example #28
Source File: TracingRedissonTest.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void test_set_multi_map() {
  RSetMultimap<String, String> map = client.getSetMultimap("set_multi_map");

  map.put("key", "value");
  assertEquals("value", map.get("key").iterator().next());

  List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(2, spans.size());
  checkSpans(spans);
  assertNull(tracer.activeSpan());
}
 
Example #29
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public <K, V> RSetMultimap<K, V> getSetMultimap(String name) {
  return new TracingRSetMultimap<>(redissonClient.getSetMultimap(name), tracingRedissonHelper);
}
 
Example #30
Source File: RedissonSetMultimapRx.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RSetRx<V> get(K key) {
    RedissonSet<V> set = (RedissonSet<V>) ((RSetMultimap<K, V>) instance).get(key);
    return RxProxyBuilder.create(commandExecutor, set, 
            new RedissonSetRx<V>(set, redisson), RSetRx.class);
}