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

The following examples show how to use org.redisson.api.RScoredSortedSet#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: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testScoredSortedSetEntryRangeReversed() {
    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<ScoredEntry<String>> r = set.entryRangeReversed(1, true, 4, false, 1, 2);
    Assert.assertEquals(2, r.size());
    ScoredEntry<String>[] a = r.toArray(new ScoredEntry[0]);
    Assert.assertEquals(2d, a[0].getScore(), 0);
    Assert.assertEquals(1d, a[1].getScore(), 0);
    Assert.assertEquals("c", a[0].getValue());
    Assert.assertEquals("b", a[1].getValue());
}
 
Example 2
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testScoredSortedSetEntryRangePositiveInf() {
    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<ScoredEntry<String>> r = set.entryRange(1, true, Double.POSITIVE_INFINITY, false, 1, 2);
    ScoredEntry<String>[] a = r.toArray(new ScoredEntry[0]);
    Assert.assertEquals(2d, a[0].getScore(), 0);
    Assert.assertEquals(3d, a[1].getScore(), 0);
    Assert.assertEquals("c", a[0].getValue());
    Assert.assertEquals("d", a[1].getValue());
}
 
Example 3
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortTo() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    assertThat(set.sortTo("test3", SortOrder.DESC)).isEqualTo(3);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("3", "2", "1");
    
    assertThat(set.sortTo("test4", SortOrder.ASC)).isEqualTo(3);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("1", "2", "3");

}
 
Example 4
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternGetAlphaLimit() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", StringCodec.INSTANCE);
    set.add(10,1);
    set.add(9, 2);
    set.add(8, 3);

    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(12);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);

    redisson.getBucket("tester1", StringCodec.INSTANCE).set("obj1");
    redisson.getBucket("tester2", StringCodec.INSTANCE).set("obj2");
    redisson.getBucket("tester3", StringCodec.INSTANCE).set("obj3");

    Collection<String> descSort = set
            .readSortAlpha("test*", Arrays.asList("tester*"), SortOrder.DESC,1,2);
    assertThat(descSort).containsExactly("obj1", "obj3");

    Collection<String> ascSort = set
            .readSortAlpha("test*", Arrays.asList("tester*"), SortOrder.ASC,1, 2);
    assertThat(ascSort).containsExactly("obj1", "obj2");
}
 
Example 5
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAndGet() throws InterruptedException {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(1, "100");

    Double res = set.addScore("100", 11);
    Assert.assertEquals(12, (double)res, 0);
    Double score = set.getScore("100");
    Assert.assertEquals(12, (double)score, 0);

    RScoredSortedSet<String> set2 = redisson.getScoredSortedSet("simple");
    set2.add(100.2, "1");

    Double res2 = set2.addScore("1", new Double(12.1));
    Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
    res2 = set2.getScore("1");
    Assert.assertTrue(new Double(112.3).compareTo(res2) == 0);
}
 
Example 6
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 7
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveRangeByScoreNegativeInf() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");
    set.add(0.5, "e");
    set.add(0.6, "f");
    set.add(0.7, "g");

    Assert.assertEquals(3, set.removeRangeByScore(Double.NEGATIVE_INFINITY, false, 0.3, true));
    assertThat(set).containsExactly("d", "e", "f", "g");
}
 
Example 8
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFirstLast() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");

    RScoredSortedSet<String> set2 = redisson.getScoredSortedSet("simple2");
    assertThat(set2.first()).isNull();
    assertThat(set2.last()).isNull();
    Assert.assertEquals("a", set.first());
    Assert.assertEquals("d", set.last());
}
 
Example 9
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadAll() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0, "1");
    set.add(1, "4");
    set.add(2, "2");
    set.add(3, "5");
    set.add(4, "3");

    assertThat(set.readAll()).containsOnly("1", "2", "4", "5", "3");
}
 
Example 10
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testCount() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0, "1");
    set.add(1, "4");
    set.add(2, "2");
    set.add(3, "5");
    set.add(4, "3");
    
    assertThat(set.count(0, true, 3, false)).isEqualTo(3);
}
 
Example 11
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortToLimit() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    assertThat(set.sortTo("test3", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "1");
    
    assertThat(set.sortTo("test4", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "3");
}
 
Example 12
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testPollFirstTimeout() {
    Assume.assumeTrue(RedisRunner.getDefaultRedisServerInstance().getRedisVersion().compareTo("5.0.0") > 0);

    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    assertThat(set.pollFirst(1, TimeUnit.SECONDS)).isNull();

    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");

    assertThat(set.pollFirst(1, TimeUnit.SECONDS)).isEqualTo("a");
    assertThat(set).containsExactly("b", "c");
}
 
Example 13
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveRangeByScore() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");
    set.add(0.5, "e");
    set.add(0.6, "f");
    set.add(0.7, "g");

    Assert.assertEquals(2, set.removeRangeByScore(0.1, false, 0.3, true));
    assertThat(set).containsExactly("a", "d", "e", "f", "g");
}
 
Example 14
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortOrderLimitAlpha(){
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("list", StringCodec.INSTANCE);
    set.add(10,"1");
    set.add(9,"3");
    set.add(8,"12");

    assertThat(set.readSortAlpha(SortOrder.DESC, 0, 2))
            .containsExactly("3", "12");
    assertThat(set.readSortAlpha(SortOrder.DESC, 1, 2))
            .containsExactly("12", "1");
}
 
Example 15
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRevRank() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");
    set.add(0.5, "e");
    set.add(0.6, "f");
    set.add(0.7, "g");

    assertThat(set.revRank("f")).isEqualTo(1);
    assertThat(set.revRank("abc")).isNull();
}
 
Example 16
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testFirstLastScore() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");

    RScoredSortedSet<String> set2 = redisson.getScoredSortedSet("simple2");
    assertThat(set2.firstScore()).isNull();
    assertThat(set2.lastScore()).isNull();
    assertThat(set.firstScore()).isEqualTo(0.1);
    assertThat(set.lastScore()).isEqualTo(0.4);
}
 
Example 17
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 18
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);
}
 
Example 19
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortOrderLimit() {
    RScoredSortedSet<Integer> set = redisson.getScoredSortedSet("list", IntegerCodec.INSTANCE);
    set.add(10, 1);
    set.add(9, 2);
    set.add(8, 3);
    
    Set<Integer> descSort = set.readSort(SortOrder.DESC, 1, 2);
    assertThat(descSort).containsExactly(2, 1);

    Set<Integer> ascSort = set.readSort(SortOrder.ASC, 1, 2);
    assertThat(ascSort).containsExactly(2, 3);
}
 
Example 20
Source File: RedissonScoredSortedSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testRank() {
    RScoredSortedSet<String> set = redisson.getScoredSortedSet("simple");
    set.add(0.1, "a");
    set.add(0.2, "b");
    set.add(0.3, "c");
    set.add(0.4, "d");
    set.add(0.5, "e");
    set.add(0.6, "f");
    set.add(0.7, "g");

    assertThat(set.revRank("d")).isEqualTo(3);
    assertThat(set.rank("abc")).isNull();
}