Java Code Examples for org.redisson.api.RStream#read()

The following examples show how to use org.redisson.api.RStream#read() . 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: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadMultiKeys() {
    RStream<String, String> stream1 = redisson.getStream("test1");
    Map<String, String> entries1 = new LinkedHashMap<>();
    entries1.put("1", "11");
    entries1.put("2", "22");
    entries1.put("3", "33");
    stream1.addAll(entries1);
    RStream<String, String> stream2 = redisson.getStream("test2");
    Map<String, String> entries2 = new LinkedHashMap<>();
    entries2.put("4", "44");
    entries2.put("5", "55");
    entries2.put("6", "66");
    stream2.addAll(entries2);
    
    Map<String, Map<StreamMessageId, Map<String, String>>> s = stream2.read(10, new StreamMessageId(0), "test1", new StreamMessageId(0));
    assertThat(s).hasSize(2);
    assertThat(s.get("test1").values().iterator().next()).isEqualTo(entries1);
    assertThat(s.get("test2").values().iterator().next()).isEqualTo(entries2);
}
 
Example 2
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadMulti() {
    RStream<String, String> stream = redisson.getStream("test");

    Map<String, String> entries1 = new LinkedHashMap<>();
    entries1.put("1", "11");
    entries1.put("3", "31");
    stream.addAll(new StreamMessageId(1), entries1, 1, false);

    Map<String, String> entries2 = new LinkedHashMap<>();
    entries2.put("5", "55");
    entries2.put("7", "77");
    stream.addAll(new StreamMessageId(2), entries2, 1, false);

    Map<String, String> entries3 = new LinkedHashMap<>();
    entries3.put("15", "05");
    entries3.put("17", "07");
    stream.addAll(new StreamMessageId(3), entries3, 1, false);
    
    Map<StreamMessageId, Map<String, String>> result = stream.read(10, new StreamMessageId(0, 0));
    assertThat(result).hasSize(3);
    assertThat(result.get(new StreamMessageId(4))).isNull();
    assertThat(result.get(new StreamMessageId(1))).isEqualTo(entries1);
    assertThat(result.get(new StreamMessageId(2))).isEqualTo(entries2);
    assertThat(result.get(new StreamMessageId(3))).isEqualTo(entries3);
}
 
Example 3
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAll() {
    RStream<String, String> stream = redisson.getStream("test1");
    assertThat(stream.size()).isEqualTo(0);

    Map<String, String> entries = new HashMap<>();
    entries.put("6", "61");
    entries.put("4", "41");
    StreamMessageId id = new StreamMessageId(12, 42);
    stream.addAll(id, entries, 10, false);
    assertThat(stream.size()).isEqualTo(1);

    Map<StreamMessageId, Map<String, String>> res = stream.read(new StreamMessageId(10, 42));
    assertThat(res.get(id).size()).isEqualTo(2);
    
    entries.clear();
    entries.put("1", "11");
    entries.put("3", "31");
    stream.addAll(new StreamMessageId(Long.MAX_VALUE), entries, 1, false);
    assertThat(stream.size()).isEqualTo(2);
}
 
Example 4
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadSingle() {
    RStream<String, String> stream = redisson.getStream("test");
    Map<String, String> entries1 = new LinkedHashMap<>();
    entries1.put("1", "11");
    entries1.put("3", "31");
    stream.addAll(new StreamMessageId(1), entries1, 1, true);
 
    Map<StreamMessageId, Map<String, String>> result = stream.read(10, new StreamMessageId(0, 0));
    assertThat(result).hasSize(1);
    assertThat(result.get(new StreamMessageId(4))).isNull();
    assertThat(result.get(new StreamMessageId(1))).isEqualTo(entries1);
}
 
Example 5
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testReadMultiKeysEmpty() {
    RStream<String, String> stream = redisson.getStream("test2");
    Map<String, Map<StreamMessageId, Map<String, String>>> s = stream.read(10, new StreamMessageId(0), "test1", new StreamMessageId(0));
    assertThat(s).isEmpty();
}
 
Example 6
Source File: RedissonStreamTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testReadEmpty() {
    RStream<String, String> stream2 = redisson.getStream("test");
    Map<StreamMessageId, Map<String, String>> result2 = stream2.read(10, new StreamMessageId(0, 0));
    assertThat(result2).isEmpty();
}