Redis设置数据值每天定时失效。比如每天早晨6点半失效
public void setEx(String key, String value, long timeout, TimeUnit unit)
只要往redis存值的时候,(指定当天失效时间 - System.currentTimeMillis() )/1000就会得到具体秒数
// 获取每一天的6:30的毫秒数 public static Long getEveryDayTime() {
Calendar calendar = Calendar.getInstance();
calendar .set(Calendar.HOUR_OF_DAY, 6);
calendar .set(Calendar.MINUTE, 30);
calendar .set(Calendar.SECOND, 0);
return calendar .getTimeInMillis();
}
每天早晨6点30失效
long expireTime = (getEveryDayTIme() - System.currentTimeMillis())/1000jimClient.setEx(key, value,expireTime, TimeUnit.SECONDS);
以上是 Redis设置数据值每天定时失效。比如每天早晨6点半失效 的全部内容, 来源链接: utcz.com/z/516598.html