update:holiday in Redis
This commit is contained in:
parent
b653c52669
commit
c2195c287a
@ -12,6 +12,7 @@ import java.util.*;
|
|||||||
@SuppressWarnings("MagicConstant")
|
@SuppressWarnings("MagicConstant")
|
||||||
public class CalendarTools {
|
public class CalendarTools {
|
||||||
public static final String REDIS_TAG = "Calendar";
|
public static final String REDIS_TAG = "Calendar";
|
||||||
|
public static final String REDIS_HOLIDAY = "holiday";
|
||||||
|
|
||||||
public static JSONObject getHoliday() {
|
public static JSONObject getHoliday() {
|
||||||
int year = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.YEAR);
|
int year = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.YEAR);
|
||||||
@ -20,7 +21,13 @@ public class CalendarTools {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static JSONObject getHoliday(String year) {
|
public static JSONObject getHoliday(String year) {
|
||||||
String get = HttpTools.get(String.format("https://timor.tech/api/holiday/year/%s", year));
|
String get;
|
||||||
|
if(RedisTools.exists(REDIS_HOLIDAY)){
|
||||||
|
get=RedisTools.get(REDIS_HOLIDAY);
|
||||||
|
}else {
|
||||||
|
get = HttpTools.get(String.format("https://timor.tech/api/holiday/year/%s", year));
|
||||||
|
RedisTools.set(REDIS_HOLIDAY,get);
|
||||||
|
}
|
||||||
JSONObject json = JSONObject.parseObject(get);
|
JSONObject json = JSONObject.parseObject(get);
|
||||||
JSONObject date = new JSONObject();
|
JSONObject date = new JSONObject();
|
||||||
JSONArray dateHoliday = new JSONArray();
|
JSONArray dateHoliday = new JSONArray();
|
||||||
|
@ -135,6 +135,15 @@ public class RedisTools {
|
|||||||
jedis.close();
|
jedis.close();
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
public static boolean exists(String key){
|
||||||
|
if(isNotInstallRedis){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Jedis jedis=getRedis();
|
||||||
|
boolean flag=jedis.exists(key);
|
||||||
|
jedis.close();
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
public static Jedis getRedis() {
|
public static Jedis getRedis() {
|
||||||
return new Jedis(host, port);
|
return new Jedis(host, port);
|
||||||
|
Loading…
Reference in New Issue
Block a user