Java Code Examples for org.redisson.api.RBuckets#get()

The following examples show how to use org.redisson.api.RBuckets#get() . 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: RedissonTransactionalBucketsTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Test
public void testSet() {
    RBucket<String> b1 = redisson.getBucket("test1");
    b1.set("1");
    RBucket<String> b2 = redisson.getBucket("test2");
    b2.set("2");
    
    RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
    RBuckets buckets = transaction.getBuckets();
    Map<String, Object> bbs = new LinkedHashMap<>();
    bbs.put("test1", "11");
    bbs.put("test2", "22");
    buckets.set(bbs);
    
    Map<String, Object> newBuckets = buckets.get("test1", "test2");
    assertThat(newBuckets).isEqualTo(bbs);
    
    transaction.commit();
    
    assertThat(redisson.getBuckets().get("test1", "test2")).isEqualTo(bbs);
    assertThat(redisson.getKeys().count()).isEqualTo(2);
}
 
Example 2
Source File: RedissonBucketsTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testCodec() {
    RBuckets buckets = redisson.getBuckets(StringCodec.INSTANCE);
    Map<String, String> items = buckets.get("buckets:A", "buckets:B", "buckets:C");

    items.put("buckets:A", "XYZ");
    items.put("buckets:B", "OPM");
    items.put("buckets:C", "123");

    buckets.set(items);
    items = buckets.get("buckets:A", "buckets:B", "buckets:C");
    Assert.assertEquals(3, items.size());
    Assert.assertEquals("XYZ", items.get("buckets:A"));
}
 
Example 3
Source File: UserRepository.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
public List<UserDO> findIn(List<Long> ids) {
    try{
        ids = ids.stream().distinct().collect(Collectors.toList());
        ListUtil.sort(ids);
        RBuckets rBuckets = redissonClient.getBuckets(JsonJacksonCodec.INSTANCE);
        Map<String, UserDO> vpMaps = rBuckets.get(ModelUtil.formatStrings(UserKeys.USER_DO_ID, ids));

        List<UserDO> list = Lists.newArrayListWithCapacity(ids.size());
        List<Long> redisIds = Lists.newArrayListWithCapacity(ids.size());
        ids.stream().forEach( id -> {
            String key = String.format(UserKeys.USER_DO_ID, id);
            if (vpMaps.containsKey(key)) {
                UserDO topicDO = vpMaps.get(key);
                if (Objects.nonNull(topicDO)) {
                    list.add(topicDO);
                    redisIds.add(id);

                    //延迟过期
                    redissonClient.getBucket(key,JsonJacksonCodec.INSTANCE)
                            .expire(AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                }
            }
        });

        List<Long> lastIds = ListUtils.removeAll(ids, redisIds);
        if (CollectionUtils.isNotEmpty(lastIds)) {
            List<UserDO> dbList =  list(lastIds);
            if (CollectionUtils.isNotEmpty(dbList)) {
                list.addAll(dbList);

                dbList.stream().forEach(topicDO -> {
                    redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, topicDO.getUid()),JsonJacksonCodec.INSTANCE)
                            .setAsync(topicDO, AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                });
            }
        }

        return list;
    }catch(Throwable th){
        throw new RepositoryException(ErrorCode.DB_ERROR.getErrorCode(),ErrorCode.DB_ERROR.getErrorMsg(),th);
    }
}