zoukankan      html  css  js  c++  java
  • redis 存取问题

          今天在写短信接口时候,要把验证码存到缓存里面。因为之前别人已经写的有案例,按照之前写的,获取 值、存到数据库,存到redis。 因为有过期时间,需要传过期时间。但是怎么都是不出来。。。 

         源码:

    @Override
    public String sendRandomCode(SmsDto smsDto, Integer seconds) throws Exception {
    String code = RandomUtils.generateNumberString(6);
    String content = code + " :为您的随机验证码";
    logger.info(smsDto.getMobile() + " 的随机验证码: " + code);
    String smsParams2 = smsParams.replace("{mobile}", smsDto.getMobile()).replace("{content}", paraTo16(content));
    Map<String, Object> result = getSend(smsUrl, smsParams2);
    // 保存发送日志
    Sms sms = this.getSmsLog(smsDto, content);
    JSONObject jsonObject = new JSONObject();
    if (MSGConstant.FALSE.equals(result.get("result"))) {
    jsonObject.put("msg", "发送失败");
    jsonObject.put("code", "102");
    return jsonObject.toString();
    }
    sms.setSendStatus("Y");
    smsService.saveSmsLog(sms);
    // 加入缓存
    System.out.println(RedisKeysUtil.common + smsDto.getMobile());
    cacheClient.add(RedisKeysUtil.common + smsDto.getMobile(), code, StringUtils.isEmpty(seconds + "") ? 600 : seconds);
    // 加入缓存计算限制发送间隔
    cacheClient.add(RedisKeysUtil.msg_length + smsDto.getMobile(), "不允许发送", 120);
    jsonObject.put("msg", "发送成功");
    jsonObject.put("code", "0");
    return jsonObject.toString();
    }


    -----------------------------------------------------------------------------------------------


    觉得没什么问题啊,最后 发现 原来是 传到redis的时间 是2、、、 2s后过期,redis是以秒为单位的。 这个小问题。。。
  • 相关阅读:
    针对安卓java入门:方法的使用
    ES6里关于字符串的拓展
    ES6里关于数字的拓展
    项目笔记:导出XML和导出全部XML功能
    项目笔记:中文转拼音工具类
    深入理解dataset及其用法
    前端插件实现图片懒加载
    Java里日期转换及日期比较大小
    iframe.contentWindow 属性:关于contentWindow和contentDocument区分
    GROUP BY 和 GROUP_CONCAT的使用
  • 原文地址:https://www.cnblogs.com/thinkingandworkinghard/p/6429944.html
Copyright © 2011-2022 走看看