数据库
首页 > 数据库> > 分页查询,redis缓存分页数据,redis双重检测

分页查询,redis缓存分页数据,redis双重检测

作者:互联网

String pageKey = RedisKeyManagement.getKey(RedisKeyManagement.ACTIVITY_BAISHI_PAGE_CACHE,
Arrays.asList(activityId.toString(),String.valueOf(current)));
Object pageObj = redisService.get(pageKey);
if(pageObj != null) {
return ApiResult.success(pageObj);
}
// 字符串对象要.intern()很重要
synchronized (("lock" + activityId + current).intern()) {
pageObj = redisService.get(pageKey);
if(pageObj != null) {
return ApiResult.success(pageObj);
}
ApiResult<PortalPageVO<PlayRecordBaseExtendVO>> apiResult = 读数据库的请求;
redisService.set(pageKey,apiResult.getData(), Constant.TEN_SECOND);
return apiResult;
}

参考:

https://blog.csdn.net/A_art_xiang/article/details/126340579

标签:缓存,return,分页,redisService,pageObj,apiResult,redis,pageKey,ApiResult
来源: https://www.cnblogs.com/maohuidong/p/16666887.html