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

The following examples show how to use org.redisson.api.RListMultimap#removeAll() . 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 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 2
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 6 votes vote down vote up
@Override
public void removeJobRecords(String jobId) {
  RMap<String, JobExecuteRecord> map = redissonClient.getMap(Container.RECORD);
  RListMultimap<String, String> sortmap = redissonClient.getListMultimap(Container.RECORD_SORT);
  List<String> list = sortmap.removeAll(jobId);
  RListMultimap<String, JobRecordStatus> statusMultimap = redissonClient
      .getListMultimap(Container.RECORD_STATUS);
  JobGroup group = findJobInfoById(jobId).getGroup();
  for (String key : list) {
    sortmap.get(Strings.EMPTY).remove(key);
    if (group != null) {
      sortmap.get(group.getGroupKey()).remove(key);
      sortmap.get(String.join(Strings.COLON, group.getGroupKey(), group.getJobKey())).remove(key);
    }
    statusMultimap.removeAll(key);
    map.remove(key);
    redissonClient.getKeys().delete(String.format(Container.EVENT_SHARDING, jobId, key));
  }
}
 
Example 3
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 4
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 5
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));
  }

}