Java Code Examples for org.redisson.api.RLexSortedSet#add()

The following examples show how to use org.redisson.api.RLexSortedSet#add() . 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 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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);
}