From 64656c7dc69d105f4426c84bc9b2830fd23e6d10 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 14 Jul 2022 13:16:59 +0800 Subject: [PATCH] =?UTF-8?q?add:redis=E6=96=B0=E5=A2=9E=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=96=B9=E6=B3=95=20update=EF=BC=9A=E7=95=AA?= =?UTF-8?q?=E5=89=A7rss=E7=9A=84redis=E8=AE=BE=E7=BD=AE=E6=9C=89=E6=95=88?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=B8=BA=E4=B8=80=E4=B8=AA=E6=9C=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/services/BangumiServiceImpl.java | 2 +- .../com/yutou/tools/utils/RedisTools.java | 50 ++++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java b/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java index 99c7a30..7e44529 100644 --- a/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java +++ b/src/main/java/com/yutou/tools/services/BangumiServiceImpl.java @@ -77,7 +77,7 @@ public class BangumiServiceImpl implements BangumiService { } String tmp=RedisTools.get(item.getBgmid()+"",1); JSONObject bangumi= tmp==null?BangumiTools.getBangumiInfoSmall(item.getBgmid()):JSONObject.parseObject(tmp); - RedisTools.set(1,item.getBgmid()+"",bangumi.toJSONString()); + RedisTools.set(1,2592000,item.getBgmid()+"",bangumi.toJSONString()); if(bangumi.containsKey("code")&&bangumi.getInteger("code")==404){ continue; } diff --git a/src/main/java/com/yutou/tools/utils/RedisTools.java b/src/main/java/com/yutou/tools/utils/RedisTools.java index f6e20a8..866026f 100644 --- a/src/main/java/com/yutou/tools/utils/RedisTools.java +++ b/src/main/java/com/yutou/tools/utils/RedisTools.java @@ -34,14 +34,19 @@ public class RedisTools { port = 6379; } - public static boolean set(int dbIndex, String key, String value) { + + public static boolean set(int dbIndex, int timeout, String key, String value) { try { if (isNotInstallRedis) { return false; } Jedis jedis = getRedis(); jedis.select(dbIndex); - String ret = jedis.set(key, value); + if (timeout == -1) { + jedis.set(key, value); + } else { + jedis.setex(key, timeout, value); + } jedis.close(); } catch (Exception e) { // TODO: handle exception @@ -51,6 +56,10 @@ public class RedisTools { return true; } + public static boolean set(int dbIndex, String key, String value) { + return set(dbIndex, -1, key, value); + } + public static boolean set(String key, String value) { return set(0, key, value); } @@ -96,7 +105,7 @@ public class RedisTools { } public static boolean remove(String key) { - return remove(key,0); + return remove(key, 0); } public static void removeLoginState(String uid) { @@ -147,32 +156,36 @@ public class RedisTools { } public static long list_add(String listName, String... value) { - Jedis jedis=getRedis(); - long index=jedis.sadd(listName,value); + Jedis jedis = getRedis(); + long index = jedis.sadd(listName, value); jedis.close(); return index; } - public static Set list_get(String listName){ - Jedis jedis=getRedis(); - Set set=jedis.smembers(listName); + + public static Set list_get(String listName) { + Jedis jedis = getRedis(); + Set set = jedis.smembers(listName); jedis.close(); - if(set==null){ - set=new HashSet<>(); + if (set == null) { + set = new HashSet<>(); } return set; } - public static boolean list_remove(String listName,String... value){ - Jedis jedis=getRedis(); - long index=jedis.srem(listName,value); + + public static boolean list_remove(String listName, String... value) { + Jedis jedis = getRedis(); + long index = jedis.srem(listName, value); jedis.close(); return index != 0; } - public static boolean list_isExist(String listName,String value){ - Jedis jedis=getRedis(); - boolean flag=jedis.sismember(listName,value); + + public static boolean list_isExist(String listName, String value) { + Jedis jedis = getRedis(); + boolean flag = jedis.sismember(listName, value); jedis.close(); return flag; } + private static class PropertyUtil { // 加载property文件到io流里面 @@ -255,7 +268,7 @@ public class RedisTools { system("cmd", message); break; case "msg": - Tools.sendServer("来自服务姬的通知~",message); + Tools.sendServer("来自服务姬的通知~", message); break; } } @@ -292,7 +305,6 @@ public class RedisTools { } - public static void bot(String value) { switch (value) { case "getip": @@ -302,6 +314,7 @@ public class RedisTools { } } } + public static void processOut(InputStream inputStream) { String tmp; @@ -319,6 +332,7 @@ public class RedisTools { System.out.println("cmd > " + str); System.out.println("线程结束"); } + public static void main(String[] args) { RedisTools.pullMsg("msg", "abc"); }