org.redisson.api.RSortedSet Java Examples
The following examples show how to use
org.redisson.api.RSortedSet.
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: RankMatchMgr.java From Almost-Famous with MIT License | 6 votes |
@Override public void remove(Actor actor, MatchEnum reason) { if (actor.getBattleMode() != BattleModeEnum.RANK) return; String match_queue_key = KeyPrefix.BattleRedisPrefix.MATCH_RANK_MODE_QUEUE + this.generatorKey(actor.getBattleRankBean().getRankId()); try { RedissonUtils.lock(redissonClient, match_queue_key); RSortedSet<SimpleActor> sortedSet = redissonClient.getSortedSet(match_queue_key); SimpleActor simpleActor = new SimpleActor(actor.getRid(), actor.getSchoolLevel(), actor.getMatchBeginTime()); sortedSet.remove(simpleActor); if (log.isDebugEnabled()) { log.debug("从段位模式匹配队列中移出玩家role={}, reason={}", actor.getRid(), reason); } } finally { RedissonUtils.unlock(redissonClient, match_queue_key); } }
Example #2
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testSort() { RSortedSet<Integer> set = redisson.getSortedSet("set"); Assert.assertTrue(set.add(2)); Assert.assertTrue(set.add(3)); Assert.assertTrue(set.add(1)); Assert.assertTrue(set.add(4)); Assert.assertTrue(set.add(10)); Assert.assertTrue(set.add(-1)); Assert.assertTrue(set.add(0)); assertThat(set).containsExactly(-1, 0, 1, 2, 3, 4, 10); Assert.assertEquals(-1, (int)set.first()); Assert.assertEquals(10, (int)set.last()); }
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: 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 #5
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 #6
Source File: RankMatchMgr.java From Almost-Famous with MIT License | 5 votes |
@Override public void run() { List<String> matchQueueAllKeys = getMatchQueueAllKeys(); synchronized (nextRunnableLock) { while (stop) { try { for (String key : matchQueueAllKeys) { try { if (!RedissonUtils.lock(redissonClient, key)) { continue; } RSortedSet<SimpleActor> sortedSet = redissonClient.getSortedSet(key); if (sortedSet.size() == 0) { continue; } long now = System.currentTimeMillis(); Collection<SimpleActor> simpleActors = sortedSet.readAll(); simpleActors.stream().forEach(simpleActor -> { long matchBeginTime = simpleActor.getMatchBeginTime(); long remainingTime = (now - matchBeginTime) / 1000; if (remainingTime > matchServerConfig.getMatchMaxWaitTime()) { //////////////////////////////// // Do something overtime sortedSet.remove(simpleActor); } }); } finally { RedissonUtils.unlock(redissonClient, key); } } nextRunnableLock.wait(3000); } catch (Exception e) { log.error("段位匹配出错{}", e); } } } }
Example #7
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 #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 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 #10
Source File: RedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAddAsync() throws InterruptedException, ExecutionException { RSortedSet<Integer> set = redisson.getSortedSet("simple"); RFuture<Boolean> future = set.addAsync(2); Assert.assertTrue(future.get()); Assert.assertTrue(set.contains(2)); }
Example #11
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 #12
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 #13
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 #14
Source File: ConcurrentRedissonSortedSetTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testAdd_SingleInstance() throws InterruptedException { final String name = "testAdd_SingleInstance"; RedissonClient r = BaseTest.createInstance(); RSortedSet<Integer> map = r.getSortedSet(name); map.clear(); int length = 5000; final List<Integer> elements = new ArrayList<Integer>(); for (int i = 1; i < length + 1; i++) { elements.add(i); } Collections.shuffle(elements); final AtomicInteger counter = new AtomicInteger(-1); testSingleInstanceConcurrency(length, rc -> { RSortedSet<Integer> set = rc.getSortedSet(name); int c = counter.incrementAndGet(); Integer element = elements.get(c); Assert.assertTrue(set.add(element)); }); Collections.sort(elements); Integer[] p = elements.toArray(new Integer[elements.size()]); assertThat(map).containsExactly(p); map.clear(); r.shutdown(); }
Example #15
Source File: TracingRedissonClient.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public <V> RSortedSet<V> getSortedSet(String name, Codec codec) { return new TracingRSortedSet<>(redissonClient.getSortedSet(name, codec), tracingRedissonHelper); }
Example #16
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 #17
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 #18
Source File: TracingRedissonClient.java From java-redis-client with Apache License 2.0 | 4 votes |
@Override public <V> RSortedSet<V> getSortedSet(String name) { return new TracingRSortedSet<>(redissonClient.getSortedSet(name), tracingRedissonHelper); }
Example #19
Source File: TracingRSortedSet.java From java-redis-client with Apache License 2.0 | 4 votes |
public TracingRSortedSet(RSortedSet<V> set, TracingRedissonHelper tracingRedissonHelper) { super(set, tracingRedissonHelper); this.set = set; this.tracingRedissonHelper = tracingRedissonHelper; }
Example #20
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 #21
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); }