标签:https fabs code current tps csdn tco demo details
/** * 校验重复请求 * * @param unrepeatKey 不能重复的key * @return true 重复 */ public boolean isRepeat(String unrepeatKey) { return !setIfAbsent(unrepeatKey, UNREPEAT_VALUE, UNREPEAT_TIME); } public Boolean setIfAbsent(String key, String value, long time) { return redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS); }
异步失效 - 处理redis expire方法存在较高的失败率
/** * 增加校验次数&&设置key过期时间 * * @param userId userId */ private void incrCertTimes(Long userId, int existKey) { String key = CertConst.CERT_KEY_PREFIX + userId; // + 1 and expire redisUtils.valueIncrement(key, 1); // 初始化时设置过期时间 if (existKey == 0 || (redisUtils.exists(key) && redisUtils.getExpire(key) == -1)) { // 第二天零点 Date zeroTime = DateUtil.getZeroTime(DateUtil.getAddDayDate(new Date(), 1)); long now = System.currentTimeMillis(); long duration = zeroTime.getTime() - now; // 单位秒 redisUtils.expire(key, (int) duration / 1000); } }
标签:https fabs code current tps csdn tco demo details
原文地址:https://www.cnblogs.com/nightOfStreet/p/11640798.html