update:holiday in Redis
This commit is contained in:
parent
b653c52669
commit
c2195c287a
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user