Java Code Examples for org.redisson.api.RSortedSet#add()
The following examples show how to use
org.redisson.api.RSortedSet#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: SortedSetExamples.java From redisson-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RSortedSet<String> sortedSet = redisson.getSortedSet("mySortedSet"); sortedSet.add("1"); sortedSet.add("2"); sortedSet.add("3"); for (String string : sortedSet) { // iteration through bulk loaded values } String firstValue = sortedSet.first(); String lastValue = sortedSet.last(); boolean removedValue = sortedSet.remove("1"); sortedSet.removeAll(Arrays.asList("1", "2", "3")); sortedSet.containsAll(Arrays.asList("4", "1", "0")); redisson.shutdown(); }
Example 2
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testRemoveAsync() throws InterruptedException, ExecutionException { RSortedSet<Integer> set = redisson.getSortedSet("simple"); set.add(1); set.add(3); set.add(7); Assert.assertTrue(set.removeAsync(1).get()); Assert.assertFalse(set.contains(1)); assertThat(set).containsExactly(3, 7); Assert.assertFalse(set.removeAsync(1).get()); assertThat(set).containsExactly(3, 7); set.removeAsync(3).get(); Assert.assertFalse(set.contains(3)); assertThat(set).containsExactly(7); }
Example 3
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testTrySetComparator() { RSortedSet<Integer> set = redisson.getSortedSet("set"); boolean setRes = set.trySetComparator(Collections.reverseOrder()); Assert.assertTrue(setRes); Assert.assertTrue(set.add(1)); Assert.assertTrue(set.add(2)); Assert.assertTrue(set.add(3)); Assert.assertTrue(set.add(4)); Assert.assertTrue(set.add(5)); assertThat(set).containsExactly(5, 4, 3, 2, 1); boolean setRes2 = set.trySetComparator(Collections.reverseOrder(Collections.reverseOrder())); Assert.assertFalse(setRes2); assertThat(set).containsExactly(5, 4, 3, 2, 1); set.clear(); boolean setRes3 = set.trySetComparator(Collections.reverseOrder(Collections.reverseOrder())); Assert.assertTrue(setRes3); set.add(3); set.add(1); set.add(2); assertThat(set).containsExactly(1, 2, 3); }
Example 4
Source File: ConcurrentRedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAddRemove_SingleInstance() throws InterruptedException, NoSuchAlgorithmException { final String name = "testAddNegative_SingleInstance"; RedissonClient r = BaseTest.createInstance(); RSortedSet<Integer> map = r.getSortedSet(name); map.clear(); int length = 1000; for (int i = 0; i < length; i++) { map.add(i); } final AtomicInteger counter = new AtomicInteger(length); final Random rnd = SecureRandom.getInstanceStrong(); testSingleInstanceConcurrency(length, rc -> { RSortedSet<Integer> set = rc.getSortedSet(name); int c = counter.incrementAndGet(); Assert.assertTrue(set.add(c)); set.remove(rnd.nextInt(length)); }); Assert.assertEquals(counter.get(), length*2); Integer prevVal = null; for (Integer val : map) { if (prevVal == null) { prevVal = val; continue; } if (val < prevVal) { Assert.fail(); } } r.shutdown(); }
Example 5
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void test1() { RSortedSet<Long> set = redisson.getSortedSet("simple", LongCodec.INSTANCE); set.add(2L); set.add(0L); set.add(1L); set.add(5L); assertThat(set.readAll()).containsExactly(0L, 1L, 2L, 5L); }
Example 6
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testReadAll() { RSortedSet<Integer> set = redisson.getSortedSet("simple"); set.add(2); set.add(0); set.add(1); set.add(5); assertThat(set.readAll()).containsExactly(0, 1, 2, 5); }
Example 7
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testIteratorNextNext() { RSortedSet<String> list = redisson.getSortedSet("simple"); list.add("1"); list.add("4"); Iterator<String> iter = list.iterator(); Assert.assertEquals("1", iter.next()); Assert.assertEquals("4", iter.next()); Assert.assertFalse(iter.hasNext()); }
Example 8
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testIteratorRemove() { RSortedSet<String> list = redisson.getSortedSet("list"); list.add("1"); list.add("4"); list.add("2"); list.add("5"); list.add("3"); for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { String value = iterator.next(); if (value.equals("2")) { iterator.remove(); } } assertThat(list).contains("1", "4", "5", "3"); int iteration = 0; for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { iterator.next(); iterator.remove(); iteration++; } Assert.assertEquals(4, iteration); Assert.assertEquals(0, list.size()); Assert.assertTrue(list.isEmpty()); }
Example 9
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testRemove() { RSortedSet<Integer> set = redisson.getSortedSet("set"); set.add(5); set.add(3); set.add(1); set.add(2); set.add(4); Assert.assertFalse(set.remove(0)); Assert.assertTrue(set.remove(3)); assertThat(set).containsExactly(1, 2, 4, 5); }
Example 10
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 4 votes |
public void testTailSet() { RSortedSet<Integer> set = redisson.getSortedSet("set"); set.add(1); set.add(2); set.add(3); set.add(4); set.add(5); SortedSet<Integer> hs = set.tailSet(3); hs.add(10); assertThat(hs).containsExactly(3, 4, 5, 10); set.remove(4); assertThat(hs).containsExactly(3, 5, 10); set.remove(3); assertThat(hs).containsExactly(5, 10); hs.add(-1); }
Example 11
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 4 votes |
public void testHeadSet() { RSortedSet<Integer> set = redisson.getSortedSet("set"); set.add(1); set.add(2); set.add(3); set.add(4); set.add(5); SortedSet<Integer> hs = set.headSet(3); hs.add(0); assertThat(hs).containsExactly(0, 1, 2); set.remove(2); assertThat(hs).containsExactly(0, 1); set.remove(3); assertThat(hs).containsExactly(0, 1); hs.add(7); }
Example 12
Source File: RedissonScoredSortedSetTest.java From redisson with Apache License 2.0 | 4 votes |
public void testTailSet() { RSortedSet<Integer> set = redisson.getSortedSet("set"); set.add(1); set.add(2); set.add(3); set.add(4); set.add(5); SortedSet<Integer> hs = set.tailSet(3); hs.add(10); assertThat(hs).containsExactly(3, 4, 5, 10); set.remove(4); assertThat(hs).containsExactly(3, 5, 10); set.remove(3); assertThat(hs).containsExactly(5, 10); hs.add(-1); }
Example 13
Source File: RedissonScoredSortedSetTest.java From redisson with Apache License 2.0 | 4 votes |
public void testHeadSet() { RSortedSet<Integer> set = redisson.getSortedSet("set"); set.add(1); set.add(2); set.add(3); set.add(4); set.add(5); SortedSet<Integer> hs = set.headSet(3); hs.add(0); assertThat(hs).containsExactly(0, 1, 2); set.remove(2); assertThat(hs).containsExactly(0, 1); set.remove(3); assertThat(hs).containsExactly(0, 1); hs.add(7); }