当前位置:网站首页>Redis存储验证码
Redis存储验证码
2022-08-10 15:58:00 【qq_45860901】
import redis.clients.jedis.Jedis;
import java.util.Random;
public class RedisConfig {
static String code = null;
public static void main(String[] args) {
//1,先判断该手机验证次数几次了,有没有超时间
//2,然后生成随机码
//3,再判断填写的随机码是否和生成的随机码相同。
verifyPhone("12345678912");
}
public static void verifyPhone(String phone){
Jedis jedis = new Jedis("192.168.110.110", 6379);
String keyPhone = "verify" + phone + "count";
String codePhone = phone + "code";
String s = jedis.get(keyPhone);
//第一次,没有key的记录,所以需要判断null
if(s == null){
jedis.setex(keyPhone, 24*60*60, "1");
}else if(Integer.valueOf(s) < 3){
//第二,三次,有记录了
jedis.incr(keyPhone);
}else {
System.out.println("今天已经超过三次");
jedis.close();
return;
}
//如果还在三次之内可以,可以执行这个获取值的操作
code = getRandomCode();
jedis.setex(codePhone, 60, code);
jedis.close();
}
public static String getRandomCode(){
Random random = new Random();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 6; ++i){
int tmp = random.nextInt(10);
builder.append(tmp);
}
return builder.toString();
}
}
边栏推荐
- Chapter II Module Encyclopedia "collections Module"
- 电商秒杀项目收获(二)
- 困扰已久的一个微信bug
- 【每日一题】【leetcode】26. 链表-链表中倒数第k个节点
- Detailed understanding of anonymous functions and all built-in functions (Part 2)
- 不同主机收不到组播消息原因分析
- 不爱生活的段子手不是好设计师|ONES 人物
- Gif动图制作怎么在线操作?一招教你快速完成gif在线制作
- MySQL command line export import database
- Opencv 图像超像素分割(SLIC、SEEDS、LSC)
猜你喜欢
随机推荐
快速申请代码签名证书方法
虚拟电厂可视化大屏,深挖痛点精准减碳
IPC:Interrupts and Signals
2025年推出 奥迪透露将推出大型SUV产品
5G NR MIB详解
Mobileye携手极氪通过OTA升级开启高级驾驶辅助新篇章
基础填空以及编程题
uniapp使用scroll-view,设置横向,内容重叠的问题解决
Mobileye joins hands with Krypton to open a new chapter in advanced driver assistance through OTA upgrade
HUAWEI CLOUD DevCloud received the highest-level certification of the first batch of cloud-native technology architecture maturity assessments by the China Academy of Information and Communications Te
一个 ABAP 开发的新浪微博语义情感分析工具
智为链接,慧享生活,荣耀智慧服务,只为 “懂” 你
关于“算力”,这篇文章值得一看
一文带你了解 HONOR Connect
Methodology of multi-living in different places
并发容器线程安全应对之道
8月Meetup | “数据调度+分析引擎”解锁企业数字化转型之路
cmake 小技巧 记录
cmake tips record
困扰已久的一个微信bug









