diff --git a/src/main/java/com/yutou/tools/utils/CalendarTools.java b/src/main/java/com/yutou/tools/utils/CalendarTools.java index c701538..c7a92c4 100644 --- a/src/main/java/com/yutou/tools/utils/CalendarTools.java +++ b/src/main/java/com/yutou/tools/utils/CalendarTools.java @@ -12,6 +12,7 @@ import java.util.*; @SuppressWarnings("MagicConstant") public class CalendarTools { public static final String REDIS_TAG = "Calendar"; + public static final String REDIS_HOLIDAY = "holiday"; public static JSONObject getHoliday() { int year = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.YEAR); @@ -20,7 +21,13 @@ public class CalendarTools { @SneakyThrows 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 date = new JSONObject(); JSONArray dateHoliday = new JSONArray(); diff --git a/src/main/java/com/yutou/tools/utils/RedisTools.java b/src/main/java/com/yutou/tools/utils/RedisTools.java index 866026f..244c495 100644 --- a/src/main/java/com/yutou/tools/utils/RedisTools.java +++ b/src/main/java/com/yutou/tools/utils/RedisTools.java @@ -135,6 +135,15 @@ public class RedisTools { jedis.close(); 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() { return new Jedis(host, port);