当前位置:网站首页>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();
}
}
边栏推荐
- x64汇编代码测试 用户模式和内核模式
- 功能测试vs.非功能测试:能否非此即彼地进行选择?
- Cesium Quick Start 4-Polylines primitive usage explanation
- 力扣+牛客--刷题记录
- Mobileye joins hands with Krypton to open a new chapter in advanced driver assistance through OTA upgrade
- 持续集成实战 —— Jenkins自动化测试环境搭建
- NPM - Cannot read properties of null (reading 'pickAlgorithm') 解决方案
- An ABAP tool that can print the browsing history of a user in the system for BSP applications
- 软件配置 | pip下载第三方库文件及配置pip源的不完全总结
- 【服务器数据恢复】raid5崩溃导致lvm信息和VXFS文件系统损坏的数据恢复案例
猜你喜欢

功能测试vs.非功能测试:能否非此即彼地进行选择?

字符串压缩(三)之短字符串压缩

“低代码”编程或将是软件开发的未来

清理空的 Jetpack Compose 应用程序模板

不爱生活的段子手不是好设计师|ONES 人物

一个 ABAP Development Tool 自定义 service endpoint 的测试工具

【Windows】将排除项添加到安全中心以避免exe被系统自动删除

Kubernetes kube-proxy工作原理

Colocate Join :ClickHouse的一种高性能分布式join查询模型

Allwinner V853 development board transplants LVGL-based 2048 games
随机推荐
【21天学习挑战赛】折半查找
【每日一题】【leetcode】25. 数组-旋转数组的最小数字
请查收 2022华为开发者大赛备赛攻略
8月Meetup | “数据调度+分析引擎”解锁企业数字化转型之路
Servlet简单项目操作
使用 ABAP 正则表达式解析 uuid 的值
uniapp使用scroll-view,设置横向,内容重叠的问题解决
【每日一题】【leetcode】26. 链表-链表中倒数第k个节点
NPM - Cannot read properties of null (reading 'pickAlgorithm') 解决方案
颜色空间
Methodology of multi-living in different places
LeetCode-692. Top K Frequent Words
photoshop入门教程
Go+:首个顺应 “三位一体” 发展潮流的编程语言
Cesium Quick Start 4-Polylines primitive usage explanation
架构设计之一——基础架构
An ABAP tool that can print the browsing history of a user in the system for BSP applications
LeetCode-876. Middle of the Linked List
LeetCode-101. Symmetric Tree
Please check the preparation guide for the 2022 Huawei Developer Competition