目前實現的方式有一定的侷限性,但是能用上,能用上就行以後再想怎麼優化,以下代碼邏輯也是有漏洞的,請主動忽略
public static String jedis(){
String yzm ="";
//連接測試環境的 Redis 服務
Jedis jedis = new Jedis("xxx.xxx.xxx.xx");
System.out.println("連接成功");
//查看服務是否運行
System.out.println("服務正在運行: "+jedis.ping());
Set<String> set =jedis.keys("imgKey*");//獲取所有的key
//System.out.println(set.size());
if(set.size()!=0){
for (String key : set) { //循環獲取每一個key對應的value
Long time = jedis.ttl(key); //查詢key的過期時間剩餘
if(time>=890){
System.out.print(key); //打印出對應的value
System.out.println("--過期時間:"+time);//打印出該value的過期時間剩餘
yzm = jedis.get(key); //獲取該key對應的value
System.out.println("驗證碼是:"+yzm);
}
}
}else {
return "當前庫中無數據,請重新生成驗證碼";
}
return yzm;
}