Search in sources :

Example 6 with RLexSortedSet

use of org.redisson.api.RLexSortedSet in project redisson by redisson.

the class RedissonScriptTest method testMulti.

@Test
public void testMulti() {
    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);
}
Also used : List(java.util.List) RLexSortedSet(org.redisson.api.RLexSortedSet) Test(org.junit.jupiter.api.Test)

Example 7 with RLexSortedSet

use of org.redisson.api.RLexSortedSet in project gora by apache.

the class RedisStore method runQuery.

private Collection<K> runQuery(Query<K, T> query) {
    Collection<K> range;
    if (isNumericKey()) {
        RScoredSortedSet<Object> index = redisInstance.getScoredSortedSet(generateIndexKey());
        Collection<ScoredEntry<Object>> rangeResponse;
        int limit = query.getLimit() > -1 ? (int) query.getLimit() : Integer.MAX_VALUE;
        if (query.getStartKey() != null && query.getEndKey() != null) {
            rangeResponse = index.entryRange(obtainDoubleValue(query.getStartKey()), true, obtainDoubleValue(query.getEndKey()), true, 0, limit);
        } else if (query.getStartKey() != null && query.getEndKey() == null) {
            rangeResponse = index.entryRange(obtainDoubleValue(query.getStartKey()), true, Double.MAX_VALUE, true, 0, limit);
        } else if (query.getStartKey() == null && query.getEndKey() != null) {
            rangeResponse = index.entryRange(Double.MIN_VALUE, true, obtainDoubleValue(query.getEndKey()), true, 0, limit);
        } else {
            rangeResponse = index.entryRange(Double.MIN_VALUE, true, Double.MAX_VALUE, true, 0, limit);
        }
        range = new ArrayList<>();
        for (ScoredEntry<Object> indexVal : rangeResponse) {
            range.add((K) indexVal.getValue());
        }
    } else {
        RLexSortedSet index = redisInstance.getLexSortedSet(generateIndexKey());
        Collection<String> rangeResponse;
        int limit = query.getLimit() > -1 ? (int) query.getLimit() : Integer.MAX_VALUE;
        if (query.getStartKey() != null && query.getEndKey() != null) {
            rangeResponse = index.range(query.getStartKey().toString(), true, query.getEndKey().toString(), true, 0, limit);
        } else if (query.getStartKey() != null && query.getEndKey() == null) {
            rangeResponse = index.rangeTail(query.getStartKey().toString(), true, 0, limit);
        } else if (query.getStartKey() == null && query.getEndKey() != null) {
            rangeResponse = index.rangeHead(query.getEndKey().toString(), true, 0, limit);
        } else {
            rangeResponse = index.stream().limit(limit).collect(Collectors.toList());
        }
        range = new ArrayList<>();
        for (String indexVal : rangeResponse) {
            range.add((K) indexVal);
        }
    }
    return range;
}
Also used : ScoredEntry(org.redisson.client.protocol.ScoredEntry) RLexSortedSet(org.redisson.api.RLexSortedSet)

Example 8 with RLexSortedSet

use of org.redisson.api.RLexSortedSet in project redisson by redisson.

the class RedissonLexSortedSetTest method testPollFirst.

@Test
public void testPollFirst() {
    RLexSortedSet set = redisson.getLexSortedSet("simple");
    Assertions.assertNull(set.pollFirst());
    set.add("a");
    set.add("b");
    set.add("c");
    Assertions.assertEquals("a", set.pollFirst());
    assertThat(set).containsExactly("b", "c");
}
Also used : RLexSortedSet(org.redisson.api.RLexSortedSet) Test(org.junit.jupiter.api.Test)

Example 9 with RLexSortedSet

use of org.redisson.api.RLexSortedSet in project redisson by redisson.

the class RedissonLexSortedSetTest method testLexRangeHead.

@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");
}
Also used : RLexSortedSet(org.redisson.api.RLexSortedSet) Test(org.junit.jupiter.api.Test)

Example 10 with RLexSortedSet

use of org.redisson.api.RLexSortedSet in project redisson by redisson.

the class RedissonLexSortedSetTest method testRemoveLexRangeHead.

@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");
    Assertions.assertEquals(2, (int) set.removeRangeHead("c", false));
    assertThat(set).containsExactly("c", "d", "e", "f", "g");
    Assertions.assertEquals(1, (int) set.removeRangeHead("c", true));
    assertThat(set).containsExactly("d", "e", "f", "g");
}
Also used : RLexSortedSet(org.redisson.api.RLexSortedSet) Test(org.junit.jupiter.api.Test)

Aggregations

RLexSortedSet (org.redisson.api.RLexSortedSet)17 Test (org.junit.jupiter.api.Test)15 List (java.util.List)1 Test (org.junit.Test)1 ScoredEntry (org.redisson.client.protocol.ScoredEntry)1