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);
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;
}

View File

@ -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<String> list_get(String listName){
Jedis jedis=getRedis();
Set<String> set=jedis.smembers(listName);
public static Set<String> list_get(String listName) {
Jedis jedis = getRedis();
Set<String> 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");
}