org.redisson.api.RSet Java Examples

The following examples show how to use org.redisson.api.RSet. 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: RedissonSetMultimapTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() {
    RSetMultimap<String, String> map = redisson.getSetMultimap("simple");
    map.put("1", "2");
    map.put("2", "3");
    assertThat(map.delete()).isTrue();
    
    RSetMultimap<String, String> map2 = redisson.getSetMultimap("simple1");
    assertThat(map2.delete()).isFalse();

    RSetMultimap<String, String> multiset = redisson.getSetMultimap( "test" );
    multiset.put("1", "01");
    multiset.put("1", "02");
    multiset.put("1", "03");
    RSet<String> set = multiset.get( "1" );

    set.delete();
    assertThat(multiset.size()).isZero();
    assertThat(multiset.get("1").size()).isZero();
}
 
Example #2
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadIntersection() {
    RSet<Integer> set = redisson.getSet("set");
    set.add(5);
    set.add(7);
    set.add(6);
    RSet<Integer> set1 = redisson.getSet("set1");
    set1.add(1);
    set1.add(2);
    set1.add(5);
    RSet<Integer> set2 = redisson.getSet("set2");
    set2.add(3);
    set2.add(4);
    set2.add(5);

    assertThat(set.readIntersection("set1", "set2")).containsOnly(5);
    assertThat(set).containsOnly(6, 5, 7);
}
 
Example #3
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testMove() throws Exception {
    RSet<Integer> set = redisson.getSet("set");
    RSet<Integer> otherSet = redisson.getSet("otherSet");

    set.add(1);
    set.add(2);

    assertThat(set.move("otherSet", 1)).isTrue();

    assertThat(set.size()).isEqualTo(1);
    assertThat(set).contains(2);

    assertThat(otherSet.size()).isEqualTo(1);
    assertThat(otherSet).contains(1);
}
 
Example #4
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAsync() throws InterruptedException, ExecutionException {
    RSet<Integer> set = redisson.getSet("simple");
    set.add(1);
    set.add(3);
    set.add(7);

    Assert.assertTrue(set.removeAsync(1).get());
    Assert.assertFalse(set.contains(1));
    assertThat(set).containsOnly(3, 7);

    Assert.assertFalse(set.removeAsync(1).get());
    assertThat(set).containsOnly(3, 7);

    set.removeAsync(3).get();
    Assert.assertFalse(set.contains(3));
    assertThat(set).contains(7);
}
 
Example #5
Source File: RedissonSessionRepository.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, RedissonSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
    if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) {
        return Collections.emptyMap();
    }
    
    RSet<String> set = getPrincipalSet(indexValue);
    
    Set<String> sessionIds = set.readAll();
    Map<String, RedissonSession> result = new HashMap<String, RedissonSession>();
    for (String id : sessionIds) {
        RedissonSession session = findById(id);
        if (session != null) {
            result.put(id, session);
        }
    }
    return result;
}
 
Example #6
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testIntersection() {
    RSet<Integer> set = redisson.getSet("set");
    set.add(5);
    set.add(6);
    RSet<Integer> set1 = redisson.getSet("set1");
    set1.add(1);
    set1.add(2);
    set1.add(3);
    RSet<Integer> set2 = redisson.getSet("set2");
    set2.add(3);
    set2.add(4);
    set2.add(5);

    assertThat(set.intersection("set1", "set2")).isEqualTo(1);
    assertThat(set).containsOnly(3);
}
 
Example #7
Source File: RedissonSession.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void delete() {
    if (map == null) {
        map = redissonManager.getMap(id);
    }
    
    if (broadcastSessionEvents) {
        RSet<String> set = redissonManager.getNotifiedNodes(id);
        set.add(redissonManager.getNodeId());
        set.expire(60, TimeUnit.SECONDS);
        map.fastPut(IS_EXPIRATION_LOCKED, true);
        map.expire(60, TimeUnit.SECONDS);
    } else {
        map.delete();
    }
    if (readMode == ReadMode.MEMORY) {
        topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
    }
    map = null;
}
 
Example #8
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddLong() throws InterruptedException, ExecutionException {
    Long sb = 1l;

    RSet<Long> set = redisson.getSet("simple_longs");
    set.add(sb);

    for (Long l : set) {
        Assert.assertEquals(sb.getClass(), l.getClass());
    }

    Object[] arr = set.toArray();

    for (Object o : arr) {
        Assert.assertEquals(sb.getClass(), o.getClass());
    }
}
 
Example #9
Source File: RedissonSession.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void delete() {
    if (map == null) {
        map = redissonManager.getMap(id);
    }
    
    if (broadcastSessionEvents) {
        RSet<String> set = redissonManager.getNotifiedNodes(id);
        set.add(redissonManager.getNodeId());
        set.expire(60, TimeUnit.SECONDS);
        map.fastPut(IS_EXPIRATION_LOCKED, true);
        map.expire(60, TimeUnit.SECONDS);
    } else {
        map.delete();
    }
    if (readMode == ReadMode.MEMORY) {
        topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
    }
    map = null;
}
 
Example #10
Source File: RedissonSession.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void delete() {
    if (map == null) {
        map = redissonManager.getMap(id);
    }
    
    if (broadcastSessionEvents) {
        RSet<String> set = redissonManager.getNotifiedNodes(id);
        set.add(redissonManager.getNodeId());
        set.expire(60, TimeUnit.SECONDS);
        map.fastPut(IS_EXPIRATION_LOCKED, true);
        map.expire(60, TimeUnit.SECONDS);
    } else {
        map.delete();
    }
    if (readMode == ReadMode.MEMORY) {
        topic.publish(new AttributesClearMessage(redissonManager.getNodeId(), getId()));
    }
    map = null;
}
 
Example #11
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadDiff() {
    RSet<Integer> set = redisson.getSet("set");
    set.add(5);
    set.add(7);
    set.add(6);
    RSet<Integer> set1 = redisson.getSet("set1");
    set1.add(1);
    set1.add(2);
    set1.add(5);
    RSet<Integer> set2 = redisson.getSet("set2");
    set2.add(3);
    set2.add(4);
    set2.add(5);

    assertThat(set.readDiff("set1", "set2")).containsOnly(7, 6);
    assertThat(set).containsOnly(6, 5, 7);
}
 
Example #12
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testDiff() {
    RSet<Integer> set = redisson.getSet("set");
    set.add(5);
    set.add(6);
    RSet<Integer> set1 = redisson.getSet("set1");
    set1.add(1);
    set1.add(2);
    set1.add(3);
    RSet<Integer> set2 = redisson.getSet("set2");
    set2.add(3);
    set2.add(4);
    set2.add(5);

    assertThat(set.diff("set1", "set2")).isEqualTo(2);
    assertThat(set).containsOnly(1, 2);
}
 
Example #13
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortToByPattern() {
    RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add(1);
    list.add(2);
    list.add(3);
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
    
    assertThat(list.sortTo("tester3", "test*", SortOrder.DESC, 1, 2)).isEqualTo(2);
    RList<String> list2 = redisson.getList("tester3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("2", "3");
    
    assertThat(list.sortTo("tester4", "test*", SortOrder.ASC, 1, 2)).isEqualTo(2);
    RList<String> list3 = redisson.getList("tester4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("2", "1");
}
 
Example #14
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortTo() {
    RSet<String> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add("1");
    list.add("2");
    list.add("3");

    assertThat(list.sortTo("test3", SortOrder.DESC)).isEqualTo(3);
    RList<String> list2 = redisson.getList("test3", StringCodec.INSTANCE);
    assertThat(list2).containsExactly("3", "2", "1");
    
    assertThat(list.sortTo("test4", SortOrder.ASC)).isEqualTo(3);
    RList<String> list3 = redisson.getList("test4", StringCodec.INSTANCE);
    assertThat(list3).containsExactly("1", "2", "3");

}
 
Example #15
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternGetAlphaLimit() {
    RSet<String> set = redisson.getSet("list", StringCodec.INSTANCE);
    set.add("1");
    set.add("2");
    set.add("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 #16
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternGetAlpha() {
    RSet<String> set = redisson.getSet("list", StringCodec.INSTANCE);
    set.add("1");
    set.add("2");
    set.add("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);
    assertThat(descSort).containsExactly("obj2", "obj1", "obj3");

    Collection<String> ascSort = set
            .readSortAlpha("test*", Arrays.asList("tester*"), SortOrder.ASC);
    assertThat(ascSort).containsExactly("obj3", "obj1", "obj2");
}
 
Example #17
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternAlphaLimit(){
    RSet<Integer> set = redisson.getSet("list", IntegerCodec.INSTANCE);
    set.add(1);
    set.add(2);
    set.add(3);

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

    Collection<Integer> descSort = set
            .readSortAlpha("test*", SortOrder.DESC,1, 2);
    assertThat(descSort).containsExactly(1, 3);

    Collection<Integer> ascSort = set
            .readSortAlpha("test*", SortOrder.ASC,1, 2);
    assertThat(ascSort).containsExactly(1, 2);
}
 
Example #18
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternAlpha(){
    RSet<Integer> set = redisson.getSet("list", IntegerCodec.INSTANCE);
    set.add(1);
    set.add(2);
    set.add(3);

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

    Collection<Integer> descSort = set
            .readSortAlpha("test*", SortOrder.DESC);
    assertThat(descSort).containsExactly(2, 1, 3);

    Collection<Integer> ascSort = set
            .readSortAlpha("test*", SortOrder.ASC);
    assertThat(ascSort).containsExactly(3, 1, 2);
}
 
Example #19
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternGetLimit() {
    RSet<String> list = redisson.getSet("list", StringCodec.INSTANCE);
    list.add("1");
    list.add("2");
    list.add("3");
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(1);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(3);
    
    redisson.getBucket("tester1", StringCodec.INSTANCE).set("obj1");
    redisson.getBucket("tester2", StringCodec.INSTANCE).set("obj2");
    redisson.getBucket("tester3", StringCodec.INSTANCE).set("obj3");
    
    Collection<String> descSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.DESC, 1, 2);
    assertThat(descSort).containsExactly("obj2", "obj1");

    Collection<String> ascSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.ASC, 1, 2);
    assertThat(ascSort).containsExactly("obj2", "obj3");
}
 
Example #20
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternGet() {
    RSet<String> list = redisson.getSet("list", StringCodec.INSTANCE);
    list.add("1");
    list.add("2");
    list.add("3");
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(1);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(3);
    
    redisson.getBucket("tester1", StringCodec.INSTANCE).set("obj1");
    redisson.getBucket("tester2", StringCodec.INSTANCE).set("obj2");
    redisson.getBucket("tester3", StringCodec.INSTANCE).set("obj3");
    
    Collection<String> descSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.DESC);
    assertThat(descSort).containsExactly("obj3", "obj2", "obj1");

    Collection<String> ascSort = list.readSort("test*", Arrays.asList("tester*"), SortOrder.ASC);
    assertThat(ascSort).containsExactly("obj1", "obj2", "obj3");
}
 
Example #21
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPatternLimit() {
    RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add(1);
    list.add(2);
    list.add(3);
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
    
    Set<Integer> descSort = list.readSort("test*", SortOrder.DESC, 1, 2);
    assertThat(descSort).containsExactly(2, 3);

    Set<Integer> ascSort = list.readSort("test*", SortOrder.ASC, 1, 2);
    assertThat(ascSort).containsExactly(2, 1);
}
 
Example #22
Source File: RedissonTransactionalSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveAll() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = t.getSet("test");
    Set<String> putSet = new HashSet<String>();
    putSet.add("4");
    putSet.add("3");
    set.removeAll(putSet);
    assertThat(s).containsOnly("1", "3");
    assertThat(set).containsOnly("1");
    
    t.commit();
    
    assertThat(s).containsOnly("1");
}
 
Example #23
Source File: RedissonTransactionalSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutAll() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    
    RTransaction t = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = t.getSet("test");
    Set<String> putSet = new HashSet<String>();
    putSet.add("4");
    putSet.add("6");
    set.addAll(putSet);
    assertThat(s).containsOnly("1", "3");
    assertThat(set).containsOnly("1", "3", "4", "6");
    
    t.commit();
    
    assertThat(s).containsOnly("1", "3", "4", "6");
}
 
Example #24
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSortOrderByPattern() {
    RSet<Integer> list = redisson.getSet("list", IntegerCodec.INSTANCE);
    list.add(1);
    list.add(2);
    list.add(3);
    
    redisson.getBucket("test1", IntegerCodec.INSTANCE).set(3);
    redisson.getBucket("test2", IntegerCodec.INSTANCE).set(2);
    redisson.getBucket("test3", IntegerCodec.INSTANCE).set(1);
    
    Set<Integer> descSort = list.readSort("test*", SortOrder.DESC);
    assertThat(descSort).containsExactly(1, 2, 3);

    Set<Integer> ascSort = list.readSort("test*", SortOrder.ASC);
    assertThat(ascSort).containsExactly(3, 2, 1);
}
 
Example #25
Source File: RedissonTransactionalSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdd() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = transaction.getSet("test");
    assertThat(set.add("4")).isTrue();
    assertThat(set.add("3")).isFalse();
    assertThat(set.contains("4")).isTrue();
    
    assertThat(s.contains("4")).isFalse();
    
    transaction.commit();
    
    assertThat(s.size()).isEqualTo(3);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isTrue();
    assertThat(s.contains("4")).isTrue();
}
 
Example #26
Source File: RedissonTransactionalSetTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemove() {
    RSet<String> s = redisson.getSet("test");
    s.add("1");
    s.add("3");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RSet<String> set = transaction.getSet("test");
    assertThat(set.contains("1")).isTrue();
    assertThat(set.remove("3")).isTrue();
    assertThat(set.remove("3")).isFalse();
    assertThat(set.remove("3")).isFalse();
    
    assertThat(s.contains("3")).isTrue();
    
    transaction.commit();
    
    assertThat(s.size()).isEqualTo(1);
    assertThat(s.contains("1")).isTrue();
    assertThat(s.contains("3")).isFalse();
}
 
Example #27
Source File: RedissonTopicTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSyncCommands() throws InterruptedException {
    RedissonClient redisson = BaseTest.createInstance();
    RTopic topic = redisson.getTopic("system_bus");
    RSet<String> redissonSet = redisson.getSet("set1");
    CountDownLatch latch = new CountDownLatch(1);
    topic.addListener(String.class, (channel, msg) -> {
        for (int j = 0; j < 1000; j++) {
            redissonSet.contains("" + j);
        }
        latch.countDown();
    });
    
    topic.publish("sometext");
    
    latch.await();
    redisson.shutdown();
}
 
Example #28
Source File: TokenServiceImpl.java    From java-tutorial with MIT License 6 votes vote down vote up
@Override
public void checkToken(HttpServletRequest request) {
    String token = request.getHeader(TOKEN_KEY);
    // header中不存在token
    if (StringUtils.isEmpty(token)) {
        token = request.getParameter(TOKEN_KEY);
        // parameter中也不存在token
        if (StringUtils.isEmpty(token)) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "token不存在");
        }
    }
    RSet<String> tokenSet = redissonClient.getSet(TOKEN_KEY);
    if (!tokenSet.isExists()) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "请勿重复请求");
    }

    if (tokenSet.remove(TOKEN_KEY)) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "请勿重复请求");
    }
}
 
Example #29
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testMoveNoMember() throws Exception {
    RSet<Integer> set = redisson.getSet("set");
    RSet<Integer> otherSet = redisson.getSet("otherSet");

    set.add(1);

    Assert.assertFalse(set.move("otherSet", 2));

    Assert.assertEquals(1, set.size());
    Assert.assertEquals(0, otherSet.size());
}
 
Example #30
Source File: RedissonSetTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSortOrderLimitAlpha(){
    RSet<String> set = redisson.getSet("list", StringCodec.INSTANCE);
    set.add("1");
    set.add("3");
    set.add("12");

    assertThat(set.readSortAlpha(SortOrder.DESC, 0, 2))
            .containsExactly("3", "12");
    assertThat(set.readSortAlpha(SortOrder.DESC, 1, 2))
            .containsExactly("12", "1");
}