随机数-- RandomUtil.randomNumbers(6)
1.jar包引用
spring-data-redis-2.3.3.RELEASE.jar
2.引用一下:
@Resource
private RedisTemplate<String, Object> redisTemplate;
3.方法中
JSONObject jsonObject = new JSONObject();
redisTemplate.opsForValue().set(IP, jsonObject);
String msg = String.valueOf(getSecondsNextEarlyMorning());
redisTemplate.expire(IP, getSecondsNextEarlyMorning(), TimeUnit.SECONDS);
/**
* 判断当前时间距离第二天凌晨的秒数
*
* @return 返回值单位为[s:秒]
*/
public Long getSecondsNextEarlyMorning() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
}