一、CRUD目的
通過redis的緩存數據庫的使用,減少DB的訪問量,進而將實現數據的同步緩存,所以使用CRUD來操作redis的數據
二、代碼
@Override
public WxPlatform SelectWxDefaultPlatformInfo(String wxAgentAddrId) {
WxAgentAddress wxAgentAddress = wxAgentAddressService.getDefaultPlatform(wxAgentAddrId);
WxPlatform platform = wxPlatformRepository.getWxDafaultPlatformInfo(wxAgentAddress.getWx_areaId());
// 判斷key是否存在
if(!redisServiceImpl.exists(RedisServiceKey.WxPlatform_REDIS_KEY)) {
// 獲取key的value
WxPlatform wxPlat = (WxPlatform) redisServiceImpl.get(RedisServiceKey.WxPlatform_REDIS_KEY);
if(wxPlat!=null && !wxPlat.getWx_agentAddressId().equals(wxAgentAddrId)) {
// 刪除key
redisServiceImpl.remove(RedisServiceKey.WxPlatform_REDIS_KEY);
}
}
// 保存key
redisServiceImpl.set(RedisServiceKey.WxPlatform_REDIS_KEY, platform);
//WxPlatform wxPlat = (WxPlatform) redisServiceImpl.get(RedisServiceKey.WxPlatform_REDIS_KEY);
return platform;
}
三、潛在規則
在操作redis中的key時,每個key都要去判斷下hashkey是否存在,然後進行業務的相關操作
鏈接:【 https://www.cnblogs.com/superfj/p/9232482.html 】