Java Code Examples for org.redisson.api.RSetMultimap#put()

The following examples show how to use org.redisson.api.RSetMultimap#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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
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 18
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 19
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 20
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();
}