瀏覽代碼

消息推送

24282 1 年之前
父節點
當前提交
d93bdb4c00

+ 2 - 1
hx-socket/src/main/java/com/fjhx/socket/event/WebSocketUserOfflineEvent.java

@@ -14,8 +14,9 @@ public class WebSocketUserOfflineEvent extends ApplicationEvent {
 
     private final MessageEntity messageEntity = new MessageEntity();
 
-    public WebSocketUserOfflineEvent(Long userId, Object message) {
+    public WebSocketUserOfflineEvent(Long userId, Integer type, Object message) {
         super(userId);
+        this.messageEntity.setType(type);
         this.messageEntity.setUserId(userId);
         this.messageEntity.setData(message);
         this.messageEntity.setCreateTime(new Date());

+ 3 - 3
hx-socket/src/main/java/com/fjhx/socket/service/WebSocketServer.java

@@ -58,7 +58,7 @@ public class WebSocketServer {
         Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.get(userId);
 
         if (sessionIdWebSocketServerMap == null) {
-            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, type, message));
             return;
         }
 
@@ -80,7 +80,7 @@ public class WebSocketServer {
         Map<Long, WebSocketServer> sessionIdWebSocketServerMap = webSocketMap.get(userId);
 
         if (sessionIdWebSocketServerMap == null) {
-            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, type, message));
             return;
         }
 
@@ -88,7 +88,7 @@ public class WebSocketServer {
         if (webSocketServer != null) {
             webSocketServer.sendMessage(type, message);
         } else {
-            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, message));
+            applicationContext.publishEvent(new WebSocketUserOfflineEvent(userId, type, message));
         }
 
     }

+ 19 - 4
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java

@@ -1,10 +1,7 @@
 package com.ruoyi.common.core.redis;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.BoundSetOperations;
-import org.springframework.data.redis.core.HashOperations;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.data.redis.core.*;
 import org.springframework.stereotype.Component;
 
 import java.util.*;
@@ -240,4 +237,22 @@ public class RedisCache {
     public Collection<String> keys(final String pattern) {
         return redisTemplate.keys(pattern);
     }
+
+    /**
+     * 获得缓存的基本对象列表
+     *
+     * @param pattern 缓存key前缀
+     * @return 对象列表
+     */
+    public Set<String> scan(String pattern) {
+        return (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
+            Set<String> keysTmp = new HashSet<>();
+            Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match(pattern).count(1000).build());
+            while (cursor.hasNext()) {
+                keysTmp.add(new String(cursor.next()));
+            }
+            return keysTmp;
+        });
+    }
+
 }