[会写代码的健身爱好者成长史]之代码记录随机获取6位数,将手机号和随机6位数的验证码存到redis中,一天一个手机号只能获取3次验证码

        Random random = new Random();
            String code = "";
            for (int i = 0; i < 6; i++) {
            int a = random.nextInt(10);
            code += a;
       }
//        long expire = redisUtil.getExpire("12345678");
//        redisUtil.set("123456789",code,1000);
        Object countKey1 =  redisUtil.get("123456789");
        String countKey = String.valueOf(countKey1);
        Jedis jedis = new Jedis();
        String s = jedis.get("Tel+123456789");
//        String s = (String) redisUtil.get("Tel+123456789");
        if (s == null){
            redisUtil.set("Tel+123456789",1,24*60*60);
        }else if (Integer.parseInt(s)<=2){
             redisUtil.incr("Tel+123456789", 1);
        }else if (Integer.parseInt(s)>2){
            System.out.println("今天已经发送了三次,请等待24小时之后重试");
            return;
        }
//        jedis.incr("123456789");
        redisUtil.set("123",code,300);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值