(原)Redis - 【三】Redis + MySQL + SpringBoot 項目中 基本的CRUD使用

一、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 】

http://www.javased.com/index.php?source_dir=spring-data-redis/src/main/java/org/springframework/data/redis/hash/JacksonHashMapper.java

https://blog.csdn.net/baidu_17353319/article/details/88979141#put(String%20h%2CObject%20hk%2CObject%20hv)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章