| @@ -40,10 +40,10 @@ public @interface RedisCache { | |||||
| boolean md5() default true ; | boolean md5() default true ; | ||||
| /** | /** | ||||
| * key 过期日期默认300秒 | |||||
| * key 过期日期默认60秒 | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| int expireTime() default 300; | |||||
| int expireTime() default 60; | |||||
| /** | /** | ||||
| * 时间单位默认为秒 | * 时间单位默认为秒 | ||||
| @@ -32,21 +32,21 @@ public class WxDateAmountRecordController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxDateAmountRecordService wxDateAmountRecordService; | private WxDateAmountRecordService wxDateAmountRecordService; | ||||
| @RedisCache(expireTime = 120) | |||||
| @RedisCache | |||||
| @ApiOperation("首页查询交易金额记录接口") | @ApiOperation("首页查询交易金额记录接口") | ||||
| @GetMapping("listOrder") | @GetMapping("listOrder") | ||||
| public ResultData listOrder() { | public ResultData listOrder() { | ||||
| return list(EnumDateAmtType.PAY_RECORD.getCode()); | return list(EnumDateAmtType.PAY_RECORD.getCode()); | ||||
| } | } | ||||
| @RedisCache(expireTime = 120) | |||||
| @RedisCache | |||||
| @ApiOperation("首页查询核销金额记录接口") | @ApiOperation("首页查询核销金额记录接口") | ||||
| @GetMapping("listVerified") | @GetMapping("listVerified") | ||||
| public ResultData listVerified() { | public ResultData listVerified() { | ||||
| return list(EnumDateAmtType.VERIFY_RECORD.getCode()); | return list(EnumDateAmtType.VERIFY_RECORD.getCode()); | ||||
| } | } | ||||
| @RedisCache(expireTime = 120) | |||||
| @RedisCache | |||||
| @ApiOperation("首页查询刷卡金额记录接口") | @ApiOperation("首页查询刷卡金额记录接口") | ||||
| @GetMapping("listMicropay") | @GetMapping("listMicropay") | ||||
| public ResultData listMicropay() { | public ResultData listMicropay() { | ||||
| @@ -40,10 +40,10 @@ public @interface RedisCache { | |||||
| boolean md5() default true ; | boolean md5() default true ; | ||||
| /** | /** | ||||
| * key 过期日期默认300秒 | |||||
| * key 过期日期默认60秒 | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| int expireTime() default 300; | |||||
| int expireTime() default 60; | |||||
| /** | /** | ||||
| * 时间单位默认为秒 | * 时间单位默认为秒 | ||||
| @@ -130,7 +130,7 @@ public class WxMallController extends BaseController { | |||||
| @ApiOperation("删除指定key") | @ApiOperation("删除指定key") | ||||
| @PostMapping("/delRedisKey") | @PostMapping("/delRedisKey") | ||||
| public ResultData delRedisKey(@RequestBody List<String> keys) { | |||||
| public ResultData delRedisKey(@RequestBody Collection<Object> keys) { | |||||
| return new ResultData(redisService.delRedisKey(keys)); | return new ResultData(redisService.delRedisKey(keys)); | ||||
| } | } | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import java.util.Collection; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Set; | import java.util.Set; | ||||
| @@ -11,12 +12,12 @@ public interface RedisService { | |||||
| * 获取热点缓存接口列表 | * 获取热点缓存接口列表 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| Set<Object> hotApi() ; | |||||
| Collection<Object> hotApi() ; | |||||
| /** | /** | ||||
| * 清除指定key | * 清除指定key | ||||
| * @param keys | * @param keys | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| boolean delRedisKey(List<String> keys) ; | |||||
| boolean delRedisKey(Collection<Object> keys) ; | |||||
| } | } | ||||
| @@ -4,9 +4,13 @@ import com.iformall.service.RedisService; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.commons.collections.CollectionUtils; | import org.apache.commons.collections.CollectionUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.dao.DataAccessException; | |||||
| import org.springframework.data.redis.core.RedisOperations; | |||||
| import org.springframework.data.redis.core.SessionCallback; | |||||
| import org.springframework.data.redis.core.StringRedisTemplate; | import org.springframework.data.redis.core.StringRedisTemplate; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Collection; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Set; | import java.util.Set; | ||||
| @@ -18,28 +22,25 @@ public class RedisServiceImpl implements RedisService { | |||||
| private StringRedisTemplate stringRedisTemplate; | private StringRedisTemplate stringRedisTemplate; | ||||
| @Override | @Override | ||||
| public Set<Object> hotApi() { | |||||
| public Collection<Object> hotApi() { | |||||
| return stringRedisTemplate.opsForHash().keys(KEY_HOT_API); | return stringRedisTemplate.opsForHash().keys(KEY_HOT_API); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean delRedisKey(List<String> keys) { | |||||
| public boolean delRedisKey(Collection<Object> keys) { | |||||
| if (CollectionUtils.isEmpty(keys)) { | if (CollectionUtils.isEmpty(keys)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| boolean result; | |||||
| stringRedisTemplate.multi(); | |||||
| try { | |||||
| stringRedisTemplate.opsForValue().getOperations().delete(keys); | |||||
| stringRedisTemplate.opsForHash().delete(KEY_HOT_API, keys.toArray()); | |||||
| result = true; | |||||
| } catch (Exception e) { | |||||
| log.error("delRedisKey error", e); | |||||
| stringRedisTemplate.discard(); | |||||
| result = false; | |||||
| } finally { | |||||
| stringRedisTemplate.exec(); | |||||
| } | |||||
| boolean result = stringRedisTemplate.execute(new SessionCallback<Boolean>() { | |||||
| @Override | |||||
| public Boolean execute(RedisOperations redisOperations) throws DataAccessException { | |||||
| redisOperations.multi(); | |||||
| redisOperations.opsForValue().getOperations().delete(keys); | |||||
| redisOperations.opsForHash().delete(KEY_HOT_API, keys.toArray()); | |||||
| redisOperations.exec(); | |||||
| return true ; | |||||
| } | |||||
| }); | |||||
| return result; | return result; | ||||
| } | } | ||||
| } | } | ||||