From 8fcea52f023500d5ada8afc533989592493e79ce Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期一, 09 五月 2022 17:41:43 +0800
Subject: [PATCH] redis工具增加list类型操作

---
 src/main/java/com/hx/redis/RedisUtil.java |  140 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 139 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/hx/redis/RedisUtil.java b/src/main/java/com/hx/redis/RedisUtil.java
index dbcfa16..1fabfae 100644
--- a/src/main/java/com/hx/redis/RedisUtil.java
+++ b/src/main/java/com/hx/redis/RedisUtil.java
@@ -198,7 +198,7 @@
      * @param hashKey   閿�
      * @return true鎴愬姛 false 澶辫触
      */
-    public Object hashGet(String hashKey,String key) {
+    public Object hashGet(String hashKey,Object key) {
         try {
             return redisTemplate.opsForHash().get(hashKey,key);
         } catch (Exception e) {
@@ -207,4 +207,142 @@
         }
     }
 
+    /**
+     * list 鏂板-宸︽彃鍏�
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object leftPush(String listKey,Object value) {
+        try {
+            return redisTemplate.opsForList().leftPush(listKey,value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鏂板-宸︽彃鍏�(瀛樺湪鎵嶆彃鍏�)
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object leftPushIfPresent(String listKey,Object value) {
+        try {
+            return redisTemplate.opsForList().leftPushIfPresent(listKey,value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鏂板-鍙虫彃鍏�(瀛樺湪鎵嶆彃鍏�)
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object rightPushIfPresent(String listKey,Object value) {
+        try {
+            return redisTemplate.opsForList().rightPushIfPresent(listKey,value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鏂板-鍙虫彃鍏�
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object rightPush(String listKey,Object value) {
+        try {
+            return redisTemplate.opsForList().rightPush(listKey,value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 寮瑰嚭-宸�
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object leftPop(String listKey) {
+        try {
+            return redisTemplate.opsForList().leftPop(listKey);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 寮瑰嚭-鍙�
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object rightPop(String listKey) {
+        try {
+            return redisTemplate.opsForList().rightPop(listKey);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鑾峰彇
+     *
+     * @param key   閿�
+     * @param index 绱㈠紩
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object listGet(String key, long index) {
+        try {
+            return redisTemplate.opsForList().index(key,index);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鑾峰彇闀垮害
+     *
+     * @param listKey   閿�
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object listSize(String listKey) {
+        try {
+            return redisTemplate.opsForList().size(listKey);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * list 鍒犻櫎
+     *
+     * @param listKey   閿�
+     * @param index index=0, 鍒犻櫎鎵�鏈夊�肩瓑浜巚alue鐨勫厓绱�; index>0, 浠庡ご閮ㄥ紑濮嬪垹闄ょ涓�涓�肩瓑浜巚alue鐨勫厓绱�; index<0, 浠庡熬閮ㄥ紑濮嬪垹闄ょ涓�涓�肩瓑浜巚alue鐨勫厓绱�
+     * @param value 鍒犻櫎鐨勫��
+     * @return true鎴愬姛 false 澶辫触
+     */
+    public Object listRemove(String listKey,long index,Object value) {
+        try {
+            return redisTemplate.opsForList().remove(listKey, index, value);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
 }

--
Gitblit v1.8.0