springboot项目各组件集成

  1. swagger-bootstrap-ui 
    1. https://blog.csdn.net/u010192145/article/details/79216037
  2. springboot多数据源项目demo
    1. ConfigurationProperties + tkmapper + druid
    2. https://www.cnblogs.com/nightOfStreet/p/11543768.html
  3. vim 复制 + 删除
    1. https://blog.csdn.net/ztf312/article/details/83025297
    2. https://segmentfault.com/a/1190000018498395?utm_source=tag-newest
  4. redis 分布式锁实践
    1. 重复
      /**
           * 校验重复请求
           *
           * @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);
          }
    2.  异步失效 - 处理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);
              }
          }
        

猜你喜欢

转载自www.cnblogs.com/nightOfStreet/p/11640798.html