org.redisson.api.RList Java Examples

The following examples show how to use org.redisson.api.RList. 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: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortToByPattern() {
    RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add(1);
    list.add(2);
    list.add(3);
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
    
    assertThat(list.sortTo("tester3", "test*", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("tester3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "3");
    
    assertThat(list.sortTo("tester4", "test*", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("tester4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "1");
}
 
Example #2
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortTo() {
    RSet<String> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add("1");
    list.add("2");
    list.add("3");

    assertThat(list.sortTo("test3", SortOrder.DESC)).isEqualTo(3);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("3", "2", "1");
    
    assertThat(list.sortTo("test4", SortOrder.ASC)).isEqualTo(3);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("1", "2", "3");

}
 
Example #3
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 #4
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortToByPattern() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
    
    assertThat(set.sortTo("tester3", "test*", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("tester3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "3");
    
    assertThat(set.sortTo("tester4", "test*", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("tester4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "1");
}
 
Example #5
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortTo() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    assertThat(set.sortTo("test3", SortOrder.DESC)).isEqualTo(3);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("3", "2", "1");
    
    assertThat(set.sortTo("test4", SortOrder.ASC)).isEqualTo(3);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("1", "2", "3");

}
 
Example #6
Source File: RedissonInstrumentationTest.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Test
void testList() {
    try (Scope scope = tracer.startRootTransaction(getClass().getClassLoader()).withName("transaction").activateInScope()) {
        RList<String> strings = redisson.getList("list1");
        strings.add("a");

        assertThat(strings.size()).isEqualTo(1);
        assertThat(strings.get(0)).isEqualTo("a");
    }

    assertTransactionWithRedisSpans("RPUSH", "LLEN", "LINDEX");
}
 
Example #7
Source File: ListMultimapCacheExamples.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();
    
    RListMultimapCache<String, Integer> multimap = redisson.getListMultimapCache("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);
    
    // set ttl = 10 seconds 
    multimap.expireKey("1", 10, TimeUnit.SECONDS);
    
    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 #8
Source File: ListExamples.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();
    
    RList<String> list = redisson.getList("myList");
    list.add("1");
    list.add("2");
    list.add("3");
    
    list.contains("1");
    
    String valueAtIndex = list.get(3);
    
    for (String string : list) {
        // iteration through bulk loaded values
    }
    
    boolean removedValue = list.remove("1");
    list.removeAll(Arrays.asList("1", "2", "3"));
    list.containsAll(Arrays.asList("4", "1", "0"));
    
    List<String> secondList = new ArrayList<>();
    secondList.add("4");
    secondList.add("5");
    list.addAll(secondList);

    // fetch all objects
    List<String> allValues = list.readAll();

    list.addAfter("3", "7");
    list.addBefore("4", "6");
    
    // use fast* methods when previous value is not required
    list.fastSet(1, "6");
    list.fastRemove(3);
    
    redisson.shutdown();
}
 
Example #9
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 #10
Source File: RedissonListMultimapValues.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public RList<V> subList(int fromIndex, int toIndex) {
    int size = size();
    if (fromIndex < 0 || toIndex > size) {
        throw new IndexOutOfBoundsException("fromIndex: " + fromIndex + " toIndex: " + toIndex + " size: " + size);
    }
    if (fromIndex > toIndex) {
        throw new IllegalArgumentException("fromIndex: " + fromIndex + " toIndex: " + toIndex);
    }

    return new RedissonSubList<V>(codec, commandExecutor, getName(), fromIndex, toIndex);
}
 
Example #11
Source File: RedissonSubList.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public RList<V> subList(int fromIndex, int toIndex) {
    if (fromIndex < this.fromIndex || toIndex >= this.toIndex.get()) {
        throw new IndexOutOfBoundsException("fromIndex: " + fromIndex + " toIndex: " + toIndex);
    }
    if (fromIndex > toIndex) {
        throw new IllegalArgumentException("fromIndex: " + fromIndex + " toIndex: " + toIndex);
    }

    return new RedissonSubList<V>(codec, commandExecutor, getName(), fromIndex, toIndex);
}
 
Example #12
Source File: RedissonListMultimapCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public RList<V> get(K key) {
    String keyHash = keyHash(key);
    String valuesName = getValuesName(keyHash);

    return new RedissonListMultimapValues<V>(codec, commandExecutor, valuesName, getTimeoutSetName(), key);
}
 
Example #13
Source File: RedissonCollectionMapReduceTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testInjector() {
    RList<String> list = getCollection();

    list.add("Alice was beginning to get very tired"); 
    
    RCollectionMapReduce<String, String, Integer> mapReduce = list.<String, Integer>mapReduce().mapper(new WordMapperInject()).reducer(new WordReducerInject());
    
    mapReduce.execute();
    assertThat(redisson.getAtomicLong("test").get()).isEqualTo(8);

    mapReduce.execute(new WordCollatorInject());
    assertThat(redisson.getAtomicLong("test").get()).isEqualTo(16 + 1);
}
 
Example #14
Source File: RedissonCollectionMapReduceTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
private RList<String> getCollection() {
    RList<String> list = null;
    if (RList.class.isAssignableFrom(mapClass)) {
        list = redisson.getList("list");
    } else if (RQueue.class.isAssignableFrom(mapClass)) {
        list = (RList<String>) redisson.<String>getQueue("queue");
    }
    return list;
}
 
Example #15
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 #16
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortToLimit() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    assertThat(set.sortTo("test3", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "1");
    
    assertThat(set.sortTo("test4", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "3");
}
 
Example #17
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortToLimit() {
    RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add(1);
    list.add(2);
    list.add(3);
    
    assertThat(list.sortTo("test3", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "1");
    
    assertThat(list.sortTo("test4", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "3");
}
 
Example #18
Source File: RedisPlayground.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRetrieveMessagesByPosition() {
    RList<String> list = redisson.getList("test-list");
    for (int i = 0; i < 10; i++) {
        list.add("message-" + i);
    }
    list.listIterator(5).forEachRemaining((m) -> {
        LOG.info("Received message={}", m);
    });
}
 
Example #19
Source File: TracingRedissonTest.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void test_list() {
  RList<Object> list = client.getList("list");

  list.add("key");
  assertTrue(list.contains("key"));

  List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(2, spans.size());
  checkSpans(spans);
  assertNull(tracer.activeSpan());
}
 
Example #20
Source File: TracingRListMultimap.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public RList<V> get(K key) {
  Span span = tracingRedissonHelper.buildSpan("get", map);
  span.setTag("key", nullable(key));
  return tracingRedissonHelper
      .decorate(span, () -> new TracingRList<>(map.get(key), tracingRedissonHelper));
}
 
Example #21
Source File: RedisPlayground.java    From synapse with Apache License 2.0 5 votes vote down vote up
public void shouldBuildReallyLargeList() {
    RList<String> list = redisson.getList("test-list");
    for (int i = 0; i < 1000000; i++) {
        list.add("message-" + i);
    }
    list.listIterator(999995).forEachRemaining((m) -> {
        LOG.info("Received message={}", m);
    });
}
 
Example #22
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
@Override
public void addJob(JobInfo jobInfo) {
  RMap<String, JobInfo> map = redissonClient.getMap(Container.JOB_INFO);
  jobInfo.setId(UUID.randomUUID().toString());
  RList<String> sortList = redissonClient.getList(Container.JOB_INFO_SORT);
  sortList.add(jobInfo.getId());
  // script
  if (JobInfo.TYPE.SCRIPT.name().equals(jobInfo.getType())) {
    JobScript script = build(jobInfo);
    redissonClient.<String, JobScript>getListMultimap(Container.JOB_INFO_SCRIPT)
        .put(jobInfo.getId(), script);
  }
  jobInfo.setScript(null);
  map.put(jobInfo.getId(), jobInfo);
}
 
Example #23
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
@Override
public List<JobInfo> queryJobInfos(int from, int to) {
  RMap<String, JobInfo> map = redissonClient.getMap(Container.JOB_INFO);
  RList<String> list = redissonClient.getList(Container.JOB_INFO_SORT);
  List<JobInfo> result = new ArrayList<>();
  for (String id : list.subList(from, Math.min(to, list.size()))) {
    result.add(map.get(id));
  }
  return result;
}
 
Example #24
Source File: RedisJobRepositoryImpl.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
private void fill(RList<String> list, List<JobExecuteRecord> records, int from, int to) {
  if (list.size() <= from) {
    return;
  }
  for (String id : list.subList(from, Math.min(to, list.size()))) {
    JobExecuteRecord record = findJobExecuteRecordById(id);
    if (record != null) {
      records.add(record);
    }
  }
}
 
Example #25
Source File: RedissionUtilsTest.java    From Redis_Learning with Apache License 2.0 5 votes vote down vote up
/** 
 * RList ӳ��Ϊ redis server��list���� 
 *  redis server ����: 
 * �鿴���м�---->keys * 
 * �鿴key������--->type testList 
 * �鿴key��ֵ ---->lrange testList 0 10 
 */  
@Test  
public void testGetRList() {  
    RList<Integer> rList=RedissionUtils.getInstance().getRList(redisson, "testList");  
    //�������  
    rList.clear();  
    Collection<Integer> c=Arrays.asList(12,45,12,34,56,78);  
    rList.addAll(c);  
    //��������  
    System.out.println(Arrays.toString(rList.toArray()));  
}
 
Example #26
Source File: RedisStorage.java    From Panako with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public long[] put(int hashtableIndex, int key, long[] newArray) {
	RList<Long> currentList = hashtables.get(hashtableIndex).get(key);
	//append the current list with the new values
	for(int i = currentList.size(); i <newArray.length ; i++){
		hashtables.get(hashtableIndex).put(key,newArray[i]);
	}		
	return newArray;
}
 
Example #27
Source File: RedisStorage.java    From Panako with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public long[] get(int hashtableIndex, int key) {
	RList<Long> values = hashtables.get(hashtableIndex).get(key);
	long[] asLongArray = new long[values.size()];
	for(int i = 0 ; i<asLongArray.length ; i++){
		asLongArray[i] = values.get(i);
	}
	return asLongArray;
}
 
Example #28
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));
  }

}
 
Example #29
Source File: TracingRList.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
public TracingRList(RList<V> list, TracingRedissonHelper tracingRedissonHelper) {
  super(list, tracingRedissonHelper);
  this.list = list;
  this.tracingRedissonHelper = tracingRedissonHelper;
}
 
Example #30
Source File: RedissonCollectionMapReduceTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
    RList<String> list = getCollection();
    
    list.add("Alice was beginning to get very tired"); 
    list.add("of sitting by her sister on the bank and");
    list.add("of having nothing to do once or twice she");
    list.add("had peeped into the book her sister was reading");
    list.add("but it had no pictures or conversations in it");
    list.add("and what is the use of a book");
    list.add("thought Alice without pictures or conversation");
    
    Map<String, Integer> result = new HashMap<>();
    result.put("to", 2);
    result.put("Alice", 2);
    result.put("get", 1);
    result.put("beginning", 1);
    result.put("sitting", 1);
    result.put("do", 1);
    result.put("by", 1);
    result.put("or", 3);
    result.put("into", 1);
    result.put("sister", 2);
    result.put("on", 1);
    result.put("a", 1);
    result.put("without", 1);
    result.put("and", 2);
    result.put("once", 1);
    result.put("twice", 1);
    result.put("she", 1);
    result.put("had", 2);
    result.put("reading", 1);
    result.put("but", 1);
    result.put("it", 2);
    result.put("no", 1);
    result.put("in", 1);
    result.put("what", 1);
    result.put("use", 1);
    result.put("thought", 1);
    result.put("conversation", 1);
    result.put("was", 2);
    result.put("very", 1);
    result.put("tired", 1);
    result.put("of", 3);
    result.put("her", 2);
    result.put("the", 3);
    result.put("bank", 1);
    result.put("having", 1);
    result.put("nothing", 1);
    result.put("peeped", 1);
    result.put("book", 2);
    result.put("pictures", 2);
    result.put("conversations", 1);
    result.put("is", 1);
    
    RCollectionMapReduce<String, String, Integer> mapReduce = list.<String, Integer>mapReduce().mapper(new WordMapper()).reducer(new WordReducer());
    assertThat(mapReduce.execute()).isEqualTo(result);
    Integer count = mapReduce.execute(new WordCollator());
    assertThat(count).isEqualTo(57);
    
    mapReduce.execute("resultMap");
    RMap<Object, Object> resultMap = redisson.getMap("resultMap");
    assertThat(resultMap).isEqualTo(result);
    resultMap.delete();
}