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

The following examples show how to use org.redisson.api.RListMultimap#get() . 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 JobInfo findJobInfoById(String id) {
  RMap<String, JobInfo> map = redissonClient.getMap(Container.JOB_INFO);
  JobInfo jobInfo = map.get(id);
  if (jobInfo == null) {
    return null;
  }
  RListMultimap<String, JobScript> scriptList = redissonClient
      .getListMultimap(Container.JOB_INFO_SCRIPT);
  RList<JobScript> list = scriptList.get(id);
  int size = list.size();
  if (size > 0) {
    JobScript script = list.get(size - 1);
    jobInfo.setScript(script.getScript());
  }
  return jobInfo;
}
 
Example 2
Source File: ReducerTask.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        this.codec = (Codec) codecClass.getConstructor().newInstance();
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    
    Injector.inject(reducer, redisson);
    
    RMap<KOut, VOut> map = redisson.getMap(resultMapName);
    RListMultimap<KOut, VOut> multimap = redisson.getListMultimap(name, codec);
    for (KOut key : multimap.keySet()) {
        if (Thread.currentThread().isInterrupted()) {
            break;
        }
        List<VOut> values = multimap.get(key);
        VOut out = reducer.reduce(key, values.iterator());
        map.put(key, out);
    }
    if (timeout > 0) {
        map.expire(timeout, TimeUnit.MILLISECONDS);
    }
    multimap.delete();
}
 
Example 3
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 4
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 5
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 6
Source File: RedissonListMultimapTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSize() {
    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.size()).isEqualTo(3);

    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 7
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 8
Source File: RedisJobLoggerImpl.java    From earth-frost with Apache License 2.0 4 votes vote down vote up
private void removeOldestLogger(String loggerId) {
  long maxLogSize = Container.get().getJobExecutorProperties().getMaxLogSize();
  if (maxLogSize < 0) {
    return;
  }

  RMap<String, String> logMap = redissonClient.getMap(Container.LOG_BIND);
  String jobId = logMap.get(loggerId);
  if (jobId == null) {
    return;
  }

  RListMultimap<String, String> sortmap = redissonClient.getListMultimap(Container.RECORD_SORT);
  RList<String> list = sortmap.get(jobId);
  long size = list.size() - maxLogSize;
  if (size <= 0) {
    return;
  }

  JobInfo job = jobRepository.findJobInfoById(jobId);
  if (job == null) {
    return;
  }

  RListMultimap<String, JobRecordStatus> statusMultimap = redissonClient
      .getListMultimap(Container.RECORD_STATUS);
  RMap<String, JobExecuteRecord> map = redissonClient.getMap(Container.RECORD);
  RList<String> logIds = redissonClient.<String, String>getListMultimap(Container.LOG_REL)
      .get(jobId);

  JobGroup group = job.getGroup();
  for (String key : list.subList(0, (int) size).readAll()) {
    sortmap.get(Strings.EMPTY).remove(key);
    if (group != null) {
      sortmap.get(String.join(Strings.COLON, group.getGroupKey(), group.getJobKey())).remove(key);
      sortmap.get(group.getGroupKey()).remove(key);
    }
    statusMultimap.removeAll(key);
    list.remove(key);
    map.remove(key);
    logMap.remove(key);
    logIds.remove(key);
    redissonClient.getKeys().delete(String.format(Container.EVENT_SHARDING, jobId, loggerId));
  }

}