update:redis新增对map的支持

This commit is contained in:
Yutousama 2022-07-26 22:45:11 +08:00
parent 788bd24d92
commit af54377bb2

View File

@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -137,9 +138,11 @@ public class RedisTools {
jedis.close();
return tmp;
}
public static boolean exists(Object key, String value) {
return exists(QQBOT_USER, key, value);
}
public static boolean exists(int db, Object key, String value) {
if (isNotInstallRedis) {
return false;
@ -185,13 +188,45 @@ public class RedisTools {
public static boolean list_isExist(String listName, String value) {
Jedis jedis = getRedis();
jedis.select(QQBOT_USER);
boolean flag = jedis.sismember(listName, value);
jedis.close();
return flag;
}
public static String getHashMap(String hashKey, String key) {
Jedis jedis = getRedis();
return jedis.hget(hashKey, key);
}
public static Map<String, String> getHashMap(String hashKey) {
return getRedis().hgetAll(hashKey);
}
public static boolean setHashMap(String hashKey, String key, String value) {
Jedis jedis = getRedis();
long l = jedis.hsetnx(hashKey, key, value);
jedis.close();
return l > 0;
}
public static boolean removeHashMap(String hashKey, String key) {
Jedis jedis = getRedis();
long l = jedis.hdel(hashKey, key);
jedis.close();
return l > 0;
}
public static boolean removeHashMap(String hashKey) {
Jedis jedis = getRedis();
long del = jedis.del(hashKey);
return del > 0;
}
public static Jedis getRedis() {
return new Jedis(host, port);
Jedis jedis = new Jedis(host, port);
jedis.select(QQBOT_USER);
return jedis;
}
public static boolean remove(String key, int index) {
@ -200,13 +235,9 @@ public class RedisTools {
}
Jedis jedis = getRedis();
jedis.select(index);
Long i = jedis.del(key);
long i = jedis.del(key);
jedis.close();
if (i > 0) {
return true;
} else {
return false;
}
return i > 0;
}
private static class PropertyUtil {
@ -324,7 +355,6 @@ public class RedisTools {
}
public static void bot(String value) {
switch (value) {
case "getip":
@ -335,9 +365,11 @@ public class RedisTools {
}
}
}
public static void processOut(InputStream inputStream) {
processOut(inputStream, null, true);
}
public static void processOut(InputStream inputStream, ObjectInterface objectInterface, boolean isOutQQBot) {
String tmp;
StringBuilder str = new StringBuilder();
@ -359,6 +391,7 @@ public class RedisTools {
QQBotManager.getInstance().sendMessage(str.toString());
}
}
public static void main(String[] args) {
RedisTools.pullMsg("msg", "abc");
}