org.redisson.api.RLexSortedSet Java Examples

The following examples show how to use org.redisson.api.RLexSortedSet. 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: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testLexRangeHeadReversed() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    assertThat(set.rangeHeadReversed("c", false)).containsExactly("b", "a");
    assertThat(set.rangeHeadReversed("c", true)).containsExactly("c", "b", "a");
    
    assertThat(set.rangeHeadReversed("c", false, 1, 1)).containsExactly("a");
    assertThat(set.rangeHeadReversed("c", true, 1, 2)).containsExactly("b", "a");
}
 
Example #2
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testLexRangeTailReversed() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assert.assertTrue(set.add("a"));
    Assert.assertFalse(set.add("a"));
    Assert.assertTrue(set.add("b"));
    Assert.assertTrue(set.add("c"));
    Assert.assertTrue(set.add("d"));
    Assert.assertTrue(set.add("e"));
    Assert.assertTrue(set.add("f"));
    Assert.assertTrue(set.add("g"));

    assertThat(set.rangeTailReversed("c", false)).containsExactly("g", "f", "e", "d");
    assertThat(set.rangeTailReversed("c", true)).containsExactly("g", "f", "e", "d", "c");
    
    assertThat(set.rangeTailReversed("c", false, 1, 2)).containsExactly("f", "e");
    assertThat(set.rangeTailReversed("c", true, 2, 2)).containsExactly("e", "d");
}
 
Example #3
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testLexRangeHead() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    assertThat(set.rangeHead("c", false)).containsExactly("a", "b");
    assertThat(set.rangeHead("c", true)).containsExactly("a", "b", "c");
    
    assertThat(set.rangeHead("c", false, 1, 1)).containsExactly("b");
    assertThat(set.rangeHead("c", true, 1, 2)).containsExactly("b", "c");
}
 
Example #4
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testLexRangeTail() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assert.assertTrue(set.add("a"));
    Assert.assertFalse(set.add("a"));
    Assert.assertTrue(set.add("b"));
    Assert.assertTrue(set.add("c"));
    Assert.assertTrue(set.add("d"));
    Assert.assertTrue(set.add("e"));
    Assert.assertTrue(set.add("f"));
    Assert.assertTrue(set.add("g"));

    assertThat(set.rangeTail("c", false)).containsExactly("d", "e", "f", "g");
    assertThat(set.rangeTail("c", true)).containsExactly("c", "d", "e", "f", "g");
    
    assertThat(set.rangeTail("c", false, 1, 2)).containsExactly("e", "f");
    assertThat(set.rangeTail("c", true, 1, 3)).containsExactly("d", "e", "f");
}
 
Example #5
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveLexRangeHead() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    Assert.assertEquals(2, (int)set.removeRangeHead("c", false));
    assertThat(set).containsExactly("c", "d", "e", "f", "g");
    Assert.assertEquals(1, (int)set.removeRangeHead("c", true));
    assertThat(set).containsExactly("d", "e", "f", "g");
}
 
Example #6
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveLexRangeTail() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assert.assertTrue(set.add("a"));
    Assert.assertFalse(set.add("a"));
    Assert.assertTrue(set.add("b"));
    Assert.assertTrue(set.add("c"));
    Assert.assertTrue(set.add("d"));
    Assert.assertTrue(set.add("e"));
    Assert.assertTrue(set.add("f"));
    Assert.assertTrue(set.add("g"));

    Assert.assertEquals(0, (int)set.removeRangeTail("z", false));

    Assert.assertEquals(4, (int)set.removeRangeTail("c", false));
    assertThat(set).containsExactly("a", "b", "c");
    Assert.assertEquals(1, (int)set.removeRangeTail("c", true));
    assertThat(set).containsExactly("a", "b");
}
 
Example #7
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFirstLast() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");

    Assert.assertEquals("a", set.first());
    Assert.assertEquals("d", set.last());
}
 
Example #8
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testLexCount() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    assertThat(set.count("b", true, "f", true)).isEqualTo(5);
    assertThat(set.count("b", false, "f", false)).isEqualTo(3);
}
 
Example #9
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testLexRangeReversed() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    assertThat(set.rangeReversed("aaa", true, "g", false)).containsExactly("f", "e", "d", "c", "b");
    assertThat(set.rangeReversed("aaa", true, "g", false, 1, 2)).containsExactly("e", "d");
}
 
Example #10
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testLexRange() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    assertThat(set.range("aaa", true, "g", false)).containsExactly("b", "c", "d", "e", "f");
    assertThat(set.range("aaa", true, "g", false, 2, 3)).containsExactly("d", "e", "f");
}
 
Example #11
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveLexRange() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");
    set.add("f");
    set.add("g");

    Assert.assertEquals(5, set.removeRange("aaa", true, "g", false));
    assertThat(set).containsExactly("a", "g");
}
 
Example #12
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPollFirst() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assert.assertNull(set.pollFirst());

    set.add("a");
    set.add("b");
    set.add("c");

    Assert.assertEquals("a", set.pollFirst());
    assertThat(set).containsExactly("b", "c");
}
 
Example #13
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPollLast() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assert.assertNull(set.pollLast());

    set.add("a");
    set.add("b");
    set.add("c");

    Assert.assertEquals("c", set.pollLast());
    assertThat(set).containsExactly("a", "b");
}
 
Example #14
Source File: RedissonLexSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testAll() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    set.addAll(Arrays.asList("foo", "bar"));
    assertThat(set.contains("foo")).isTrue();
    assertThat(set.contains("bar")).isTrue();
    assertThat(set.contains("123")).isFalse();
}
 
Example #15
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testLexSortedSet() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");

    set.add("a");
    set.add("b");
    set.add("c");
    set.add("d");
    set.add("e");

    Collection<String> r = set.range("b", true, "e", false, 1, 2);
    String[] a = r.toArray(new String[0]);
    Assert.assertArrayEquals(new String[]{"c", "d"}, a);
}
 
Example #16
Source File: RedissonScriptTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMulti() throws InterruptedException, ExecutionException {
    RLexSortedSet idx2 = redisson.getLexSortedSet("ABCD17436");
    
    Long l = new Long("1506524856000");
    for (int i = 0; i < 100; i++) {
        String s = "DENY" + "\t" + "TESTREDISSON" + "\t"
                + Long.valueOf(l) + "\t" + "helloworld_hongqin";
        idx2.add(s);
        l = l + 1;
    }

    String max = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856099'";
    String min = "'[DENY" + "\t" + "TESTREDISSON" + "\t" + "1506524856000'";
     String luaScript1= "local d = {}; d[1] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,5); ";
     luaScript1=  luaScript1 + " d[2] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,15); ";
     luaScript1=  luaScript1 + " d[3] = redis.call('zrevrangebylex','ABCD17436'," +max+","+min+",'LIMIT',0,25); ";
     luaScript1 = luaScript1 + " return d;";
 
     List<List<Object>> objs = redisson.getScript(StringCodec.INSTANCE).eval(RScript.Mode.READ_ONLY,
            luaScript1,
            RScript.ReturnType.MULTI, Collections.emptyList());            
    
    assertThat(objs).hasSize(3);
    assertThat(objs.get(0)).hasSize(5);
    assertThat(objs.get(1)).hasSize(15);
    assertThat(objs.get(2)).hasSize(25);
}
 
Example #17
Source File: LexSortedSetExamples.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();
    
    RLexSortedSet set = redisson.getLexSortedSet("sortedSet");
    set.add("1");
    set.add("2");
    set.add("3");
    
    for (String string : set) {
        // iteration through bulk loaded values
    }

    Set<String> newValues = new HashSet<>();
    newValues.add("4");
    newValues.add("5");
    newValues.add("6");
    set.addAll(newValues);
    
    set.contains("4");
    set.containsAll(Arrays.asList("3", "4", "5"));
    
    String firstValue = set.first();
    String lastValue = set.last();
    
    String polledFirst = set.pollFirst();
    String polledLast = set.pollLast();
    
    redisson.shutdown();
    
    // use read method to fetch all objects
    Collection<String> allValues = set.readAll();
    
    redisson.shutdown();
}
 
Example #18
Source File: TracingRLexSortedSet.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
public TracingRLexSortedSet(RLexSortedSet set, TracingRedissonHelper tracingRedissonHelper) {
  super(set, tracingRedissonHelper);
  this.set = set;
  this.tracingRedissonHelper = tracingRedissonHelper;
}
 
Example #19
Source File: RedissonLexSortedSetRx.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonLexSortedSetRx(RLexSortedSet instance) {
    this.instance = instance;
}
 
Example #20
Source File: RedissonLexSortedSetReactive.java    From redisson with Apache License 2.0 4 votes vote down vote up
public RedissonLexSortedSetReactive(RLexSortedSet instance) {
    this.instance = instance;
}
 
Example #21
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RLexSortedSet getLexSortedSet(String name) {
  return new TracingRLexSortedSet(redissonClient.getLexSortedSet(name), tracingRedissonHelper);
}