Java Code Examples for org.redisson.api.RScoredSortedSet#valueRange()

The following examples show how to use org.redisson.api.RScoredSortedSet#valueRange() . 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: LeisureMatchMgr.java    From Almost-Famous with MIT License 5 votes vote down vote up
@Override
public void run() {
    synchronized (nextRunnableLock) {
        while (stop) {
            try {
                try {
                    if (!RedissonUtils.lock(redissonClient, match_leisure_mode_queue_key)) {
                        continue;
                    }
                    long now = System.currentTimeMillis();
                    RScoredSortedSet<SimpleActor> scoredSortedSet = redissonClient.getScoredSortedSet(match_leisure_mode_queue_key);
                    Collection<SimpleActor> simpleActors = scoredSortedSet.valueRange(Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true);
                    for (SimpleActor simpleActor : simpleActors) {
                        long matchBeginTime = simpleActor.getMatchBeginTime();
                        long remainingTime = (now - matchBeginTime) / 1000;
                        if (matchServerConfig.getMatchMaxWaitTime() > remainingTime)
                            continue;
                        ////////////////////////////////
                        // Do something overtime
                        scoredSortedSet.remove(simpleActor);
                    }
                }  finally {
                    RedissonUtils.unlock(redissonClient, match_leisure_mode_queue_key);
                }
                nextRunnableLock.wait(3000);
            } catch (Exception e) {
                log.error("休闲匹配出错{}", e);
            }
        }
    }
}
 
Example 2
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueRange() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("simple");
    set.add(0, 1);
    set.add(1, 2);
    set.add(2, 3);
    set.add(3, 4);
    set.add(4, 5);
    set.add(4, 5);

    Collection<Integer> vals = set.valueRange(0, -1);
    assertThat(vals).containsExactly(1, 2, 3, 4, 5);
}
 
Example 3
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScoredSortedSetValueRangeLimit() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");

    set.add(0, "a");
    set.add(1, "b");
    set.add(2, "c");
    set.add(3, "d");
    set.add(4, "e");

    Collection<String> r = set.valueRange(1, true, 4, false, 1, 2);
    assertThat(r).containsExactly("c", "d");
}
 
Example 4
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScoredSortedSetValueRange() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");

    set.add(0, "a");
    set.add(1, "b");
    set.add(2, "c");
    set.add(3, "d");
    set.add(4, "e");

    Collection<String> r = set.valueRange(1, true, 4, false);
    assertThat(r).containsExactly("b", "c", "d");
}
 
Example 5
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScoredSortedSetValueRangeNegativeInf() {
    RScoredSortedSet<String> set = redisson.<String>getScoredSortedSet("simple");

    set.add(0, "a");
    set.add(1, "b");
    set.add(2, "c");
    set.add(3, "d");
    set.add(4, "e");

    Collection<String> r = set.valueRange(Double.NEGATIVE_INFINITY, true, 4, false, 1, 2);
    String[] a = r.toArray(new String[0]);
    Assert.assertArrayEquals(new String[]{"b", "c"}, a);
}
 
Example 6
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testScoredSortedSetValueRangePositiveInf() {
    RScoredSortedSet<String> set = redisson.<String>getScoredSortedSet("simple");

    set.add(0, "a");
    set.add(1, "b");
    set.add(2, "c");
    set.add(3, "d");
    set.add(4, "e");

    Collection<String> r = set.valueRange(1, true, Double.POSITIVE_INFINITY, false, 1, 2);
    String[] a = r.toArray(new String[0]);
    Assert.assertArrayEquals(new String[]{"c", "d"}, a);
}