add:redis新增超时设置方法

update:番剧rss的redis设置有效时间为一个月
This commit is contained in:
Yutousama 2022-07-14 13:16:59 +08:00
parent 3fb9220e72
commit 64656c7dc6
2 changed files with 33 additions and 19 deletions

View File

@ -77,7 +77,7 @@ public class BangumiServiceImpl implements BangumiService {
} }
String tmp=RedisTools.get(item.getBgmid()+"",1); String tmp=RedisTools.get(item.getBgmid()+"",1);
JSONObject bangumi= tmp==null?BangumiTools.getBangumiInfoSmall(item.getBgmid()):JSONObject.parseObject(tmp); 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){ if(bangumi.containsKey("code")&&bangumi.getInteger("code")==404){
continue; continue;
} }

View File

@ -34,14 +34,19 @@ public class RedisTools {
port = 6379; 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 { try {
if (isNotInstallRedis) { if (isNotInstallRedis) {
return false; return false;
} }
Jedis jedis = getRedis(); Jedis jedis = getRedis();
jedis.select(dbIndex); jedis.select(dbIndex);
String ret = jedis.set(key, value); if (timeout == -1) {
jedis.set(key, value);
} else {
jedis.setex(key, timeout, value);
}
jedis.close(); jedis.close();
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@ -51,6 +56,10 @@ public class RedisTools {
return true; 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) { public static boolean set(String key, String value) {
return set(0, key, value); return set(0, key, value);
} }
@ -96,7 +105,7 @@ public class RedisTools {
} }
public static boolean remove(String key) { public static boolean remove(String key) {
return remove(key,0); return remove(key, 0);
} }
public static void removeLoginState(String uid) { public static void removeLoginState(String uid) {
@ -147,32 +156,36 @@ public class RedisTools {
} }
public static long list_add(String listName, String... value) { public static long list_add(String listName, String... value) {
Jedis jedis=getRedis(); Jedis jedis = getRedis();
long index=jedis.sadd(listName,value); long index = jedis.sadd(listName, value);
jedis.close(); jedis.close();
return index; return index;
} }
public static Set<String> list_get(String listName){
Jedis jedis=getRedis(); public static Set<String> list_get(String listName) {
Set<String> set=jedis.smembers(listName); Jedis jedis = getRedis();
Set<String> set = jedis.smembers(listName);
jedis.close(); jedis.close();
if(set==null){ if (set == null) {
set=new HashSet<>(); set = new HashSet<>();
} }
return set; return set;
} }
public static boolean list_remove(String listName,String... value){
Jedis jedis=getRedis(); public static boolean list_remove(String listName, String... value) {
long index=jedis.srem(listName,value); Jedis jedis = getRedis();
long index = jedis.srem(listName, value);
jedis.close(); jedis.close();
return index != 0; return index != 0;
} }
public static boolean list_isExist(String listName,String value){
Jedis jedis=getRedis(); public static boolean list_isExist(String listName, String value) {
boolean flag=jedis.sismember(listName,value); Jedis jedis = getRedis();
boolean flag = jedis.sismember(listName, value);
jedis.close(); jedis.close();
return flag; return flag;
} }
private static class PropertyUtil { private static class PropertyUtil {
// 加载property文件到io流里面 // 加载property文件到io流里面
@ -255,7 +268,7 @@ public class RedisTools {
system("cmd", message); system("cmd", message);
break; break;
case "msg": case "msg":
Tools.sendServer("来自服务姬的通知~",message); Tools.sendServer("来自服务姬的通知~", message);
break; break;
} }
} }
@ -292,7 +305,6 @@ public class RedisTools {
} }
public static void bot(String value) { public static void bot(String value) {
switch (value) { switch (value) {
case "getip": case "getip":
@ -302,6 +314,7 @@ public class RedisTools {
} }
} }
} }
public static void processOut(InputStream inputStream) { public static void processOut(InputStream inputStream) {
String tmp; String tmp;
@ -319,6 +332,7 @@ public class RedisTools {
System.out.println("cmd > " + str); System.out.println("cmd > " + str);
System.out.println("线程结束"); System.out.println("线程结束");
} }
public static void main(String[] args) { public static void main(String[] args) {
RedisTools.pullMsg("msg", "abc"); RedisTools.pullMsg("msg", "abc");
} }