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

The following examples show how to use org.redisson.api.RListMultimap#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: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 6 votes vote down vote up
@Override
public String addJobRecord(JobExecuteRecord record) {
  RMap<String, JobExecuteRecord> map = redissonClient.getMap(Container.RECORD);
  map.put(record.getId(), record);

  // 全部
  RListMultimap<String, String> sortmap = redissonClient.getListMultimap(Container.RECORD_SORT);
  sortmap.put(Strings.EMPTY, record.getId());
  // jobId
  sortmap.put(record.getJobId(), record.getId());

  JobInfo info = findJobInfoById(record.getJobId());
  JobGroup group = info.getGroup();
  if (Objects.equals(JobInfo.TYPE.BEAN.name(), info.getType())) {
    // groupKey
    sortmap.put(group.getGroupKey(), record.getId());
    // jobKey
    sortmap
        .put(String.join(Strings.COLON, group.getGroupKey(), group.getJobKey()), record.getId());
  } else if (group != null && group.getGroupKey() != null) {
    // groupKey
    sortmap.put(group.getGroupKey(), record.getId());
  }
  return record.getId();
}
 
Example 2
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 6 votes vote down vote up
@Override
public void updateJob(JobInfo jobInfo) {
  RMap<String, JobInfo> map = redissonClient.getMap(Container.JOB_INFO);
  // script
  RListMultimap<String, JobScript> scriptList = redissonClient
      .getListMultimap(Container.JOB_INFO_SCRIPT);
  if (jobInfo.getScript() != null && JobInfo.TYPE.SCRIPT.name().equals(jobInfo.getType())) {
    JobInfo local = map.get(jobInfo.getId());
    if (!Objects.equals(jobInfo.getType(), local.getType())) {
      JobScript script = build(jobInfo);
      scriptList.removeAll(jobInfo.getId());
      scriptList.put(jobInfo.getId(), script);
    }
  } else if (JobInfo.TYPE.BEAN.name().equals(jobInfo.getType())) {
    scriptList.removeAll(jobInfo.getId());
  }
  jobInfo.setScript(null);
  map.put(jobInfo.getId(), jobInfo);
}
 
Example 3
Source File: Collector.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public void emit(K key, V value) {
    try {
        ByteBuf encodedKey = codec.getValueEncoder().encode(key);
        long hash = Hash.hash64(encodedKey);
        encodedKey.release();
        int part = (int) Math.abs(hash % parts);
        String partName = name + ":" + part;
        
        RListMultimap<K, V> multimap = client.getListMultimap(partName, codec);
        multimap.put(key, value);
        if (timeout > 0 && !expirationsBitSet.get(part)) {
            multimap.expire(timeout, TimeUnit.MILLISECONDS);
            expirationsBitSet.set(part);
        }
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 4
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPut() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("{multi.map}.some.key");
    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(5);

    List<SimpleValue> s1 = map.get(new SimpleKey("0"));
    assertThat(s1).containsExactly(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"), new SimpleValue("3"));

    List<SimpleValue> allValues = map.getAll(new SimpleKey("0"));
    assertThat(allValues).containsExactly(new SimpleValue("1"), new SimpleValue("2"), new SimpleValue("3"), new SimpleValue("3"));

    List<SimpleValue> s2 = map.get(new SimpleKey("3"));
    assertThat(s2).containsExactly(new SimpleValue("4"));
}
 
Example 5
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeySet() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("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 6
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);
}
 
Example 7
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRange() {
    RListMultimap<Integer, Integer> map = redisson.getListMultimap("test1");
    map.put(1, 1);
    map.put(1, 2);
    map.put(1, 3);
    map.put(1, 4);
    map.put(1, 5);

    assertThat(map.get(1).range(1)).containsExactly(1, 2);
    assertThat(map.get(1).range(1, 3)).containsExactly(2, 3, 4);
}
 
Example 8
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsEntry() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("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 9
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsValue() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("{1}test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));

    assertThat(map.containsValue(new SimpleValue("1"))).isTrue();
    assertThat(map.containsValue(new SimpleValue("0"))).isFalse();
}
 
Example 10
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testContainsKey() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    assertThat(map.containsKey(new SimpleKey("0"))).isTrue();
    assertThat(map.containsKey(new SimpleKey("1"))).isFalse();
}
 
Example 11
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAll() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));

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

    List<SimpleValue> values2 = map.removeAll(new SimpleKey("0"));
    assertThat(values2).isEmpty();
}
 
Example 12
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveAllFromCollection() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("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 13
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeySize() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("2"));
    map.put(new SimpleKey("1"), new SimpleValue("4"));

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

    assertThat(map.fastRemove(new SimpleKey("0"))).isEqualTo(1);

    List<SimpleValue> s = map.get(new SimpleKey("0"));
    assertThat(s).isEmpty();
    assertThat(map.size()).isEqualTo(1);
}
 
Example 14
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testValues() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("3"));
    map.put(new SimpleKey("2"), new SimpleValue("5"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.values().size()).isEqualTo(5);
    assertThat(map.values()).containsOnly(new SimpleValue("1"), new SimpleValue("1"), new SimpleValue("3"), new SimpleValue("5"), new SimpleValue("4"));
}
 
Example 15
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadAllKeySet() {
    RListMultimap<String, String> map = redisson.getListMultimap("test1");
    map.put("1", "4");
    map.put("2", "5");
    map.put("3", "6");

    assertThat(map.readAllKeySet()).containsExactly("1", "2", "3");
}
 
Example 16
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testDelete() {
    RListMultimap<String, String> testList = redisson.getListMultimap( "test" );
    testList.put("1", "01");
    testList.put("1", "02");
    testList.put("1", "03");
    RList<String> list = testList.get( "1" );

    list.delete();
    assertThat(testList.size()).isZero();
    assertThat(testList.get("1").size()).isZero();
}
 
Example 17
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 18
Source File: TracingRedissonTest.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void test_list_multi_map() {
  RListMultimap<String, String> map = client.getListMultimap("list_multi_map");

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

  List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(3, spans.size());
  checkSpans(spans);
  assertNull(tracer.activeSpan());
}
 
Example 19
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
@Override
public void addJobScript(JobScript script) {
  RListMultimap<String, JobScript> scriptList = redissonClient
      .getListMultimap(Container.JOB_INFO_SCRIPT);
  script.setId(UUID.randomUUID().toString());
  script.setTime(Date.from(ZonedDateTime.now().toInstant()));
  scriptList.put(script.getJobId(), script);
  if (scriptList.get(script.getJobId()).size() > Container.get().getSystemProperties()
      .getMaxScriptHistory()) {
    scriptList.get(script.getJobId()).remove(0);
  }
}
 
Example 20
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntrySet() {
    RListMultimap<SimpleKey, SimpleValue> map = redisson.getListMultimap("test1");
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("0"), new SimpleValue("1"));
    map.put(new SimpleKey("3"), new SimpleValue("4"));

    assertThat(map.entries().size()).isEqualTo(3);
    List<Map.Entry<SimpleKey, SimpleValue>> testMap = new ArrayList<Map.Entry<SimpleKey, SimpleValue>>();
    testMap.add(new AbstractMap.SimpleEntry(new SimpleKey("0"), new SimpleValue("1")));
    testMap.add(new AbstractMap.SimpleEntry(new SimpleKey("0"), new SimpleValue("1")));
    testMap.add(new AbstractMap.SimpleEntry(new SimpleKey("3"), new SimpleValue("4")));
    assertThat(map.entries()).containsOnlyElementsOf(testMap);
}