1.5K Star 12.2K Fork 3.3K

GVP轨迹 / J-IM

 / 详情

数据持久化部分有点问题

待办的
创建于  
2021-01-27 17:20

获取历史数据那里,感觉人家只是实现了功能,压根没考虑使用场景。
当前获取历史数据的接口,得到的返回值是从数据库最开始的时候开始计数的。而实际上,我们要的是逆序的。
jim获取历史消息这里功能很弱,后期可能需要我们自己来实现相关的功能。

/**
 * 返回有序集 key 中, score 值介于 max 和 min 之间(默认包括等于 max 或 min )的所有的成员。
 * 有序集成员按 score 值递减(从大到小)的次序排列。
 *
 * @param key key
 * @param max score最大值
 * @param min score最小值
 * @param offset 偏移量(类似LIMIT 0,10)
 * @param count  数量
 * @return 指定区间内,带有 score 值(可选)的有序集成员的列表
 */
public Set<String> revrangeByScoreWithSortedSet(final String key, final double max, final double min, final int offset, final int count) {
    return new Executor<Set<String>>(jedisPool) {
        @Override
        Set<String> execute() {
            //因为总是出错我就直接这么写了
            double t_max = max > min ? max:min;
            double t_min = min < max ? min:max;
            return jedis.zrevrangeByScore(key, max, min, offset, count);
        }
    }.getResult();
}
//反向获取
public List<String> revSortSetGetAll(String key, double min, double max, int offset, int count) {
    if (StringUtils.isBlank(key)) {
        return null;
    }
    try {
        Set<String> dataSet = JedisTemplate.me().revrangeByScoreWithSortedSet(cacheKey(cacheName, key), max, min, offset, count);
        if (dataSet == null) {
            return null;
        }
        return new ArrayList<String>(dataSet);
    } catch (Exception e) {
        logger.error(e.toString(), e);
    }
    return null;
}

//

private List<String> getHistoryMessage(String historyKey, Double beginTime, Double endTime, Integer offset, Integer count) {
        boolean isTimeBetween = (beginTime != null && endTime != null);
        boolean isPage = (offset != null && count != null);
        RedisCache storeCache = RedisCacheManager.getCache(STORE);
        //消息区间,不分页
        if (isTimeBetween && !isPage) {
            return storeCache.sortSetGetAll(historyKey, beginTime, endTime);
            //消息区间,并且分页;
        } else if (isTimeBetween && isPage) {
//            return storeCache.sortSetGetAll(historyKey, beginTime, endTime, offset, count);
            return storeCache.revSortSetGetAll(historyKey, beginTime, endTime, offset, count);
            //所有消息,并且分页;
        } else if (isPage) {
//            return storeCache.sortSetGetAll(historyKey, 0, Double.MAX_VALUE, offset, count);
            return storeCache.revSortSetGetAll(historyKey, 0, Double.MAX_VALUE, offset, count);
            //所有消息,不分页;
        } else {
            return storeCache.sortSetGetAll(historyKey);
        }
    }

评论 (2)

lanxia 创建了任务
lanxia 关联仓库设置为轨迹/J-IM
lanxia 修改了标题
lanxia 修改了描述
展开全部操作日志

建议数据持久化部分自己写吧

群里的一位小伙伴重写了。

【四级】外语学者陈清泉 16:53:53
蓝黑墨水二代  
有没有人尝试过jim的获取历史记录的功能
@蓝黑墨水二代 数据的获取和持久化我全部都改掉了

【四级】外语学者陈清泉 16:54:44
我也建议你这样做, 他原本的jar包里面有些东西是无法满足实际业务需要的, 但是好在他提供了command.register , 点赞

你好,能不能拉我进群一下

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
60075 lanxiaziyi oschina 1609138580
Java
1
https://gitee.com/xchao/j-im.git
git@gitee.com:xchao/j-im.git
xchao
j-im
J-IM

搜索帮助