码迷,mamicode.com
首页 > 编程语言 > 详细

springboot项目各组件集成

时间:2019-10-09 12:55:22      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:https   fabs   code   current   tps   csdn   tco   demo   details   

  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);
              }
          }

       

        

springboot项目各组件集成

标签:https   fabs   code   current   tps   csdn   tco   demo   details   

原文地址:https://www.cnblogs.com/nightOfStreet/p/11640798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!