代码拉取完成,页面将自动刷新
获取历史数据那里,感觉人家只是实现了功能,压根没考虑使用场景。
当前获取历史数据的接口,得到的返回值是从数据库最开始的时候开始计数的。而实际上,我们要的是逆序的。
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);
}
}
建议数据持久化部分自己写吧
群里的一位小伙伴重写了。
【四级】外语学者陈清泉 16:53:53
蓝黑墨水二代
有没有人尝试过jim的获取历史记录的功能
@蓝黑墨水二代 数据的获取和持久化我全部都改掉了
【四级】外语学者陈清泉 16:54:44
我也建议你这样做, 他原本的jar包里面有些东西是无法满足实际业务需要的, 但是好在他提供了command.register , 点赞
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
登录 后才可以发表评论