From c36044e6e49ffffa707b83c0d4f23e86340a8b23 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 25 Jul 2022 12:34:54 +0800 Subject: [PATCH] =?UTF-8?q?add:Redis=E6=96=B0=E5=A2=9E=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/utlis/RedisTools.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java index 082ee12..cd82f42 100644 --- a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java @@ -13,6 +13,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.HashSet; import java.util.Properties; import java.util.Set; @@ -155,6 +156,40 @@ public class RedisTools { return flag; } + public static long list_add(String listName, String... value) { + Jedis jedis = getRedis(); + jedis.select(QQBOT_USER); + long index = jedis.sadd(listName, value); + jedis.close(); + return index; + } + + public static Set list_get(String listName) { + Jedis jedis = getRedis(); + jedis.select(QQBOT_USER); + Set set = jedis.smembers(listName); + jedis.close(); + if (set == null) { + set = new HashSet<>(); + } + return set; + } + + public static boolean list_remove(String listName, String... value) { + Jedis jedis = getRedis(); + jedis.select(QQBOT_USER); + long index = jedis.srem(listName, value); + jedis.close(); + return index != 0; + } + + 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 Jedis getRedis() { return new Jedis(host, port); }