Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis中看不到保存的会话的key #957

Open
stevenxu79 opened this issue Jan 24, 2024 · 1 comment
Open

redis中看不到保存的会话的key #957

stevenxu79 opened this issue Jan 24, 2024 · 1 comment

Comments

@stevenxu79
Copy link

我采用RedissonStoreFactory保存会话到redis时客户端正常连接,redis监控到有"PUBLISH" connect信息,但是为什么在redis中看不到保存的会话的key呢?

@stevenxu79
Copy link
Author

stevenxu79 commented Jan 27, 2024

服务端代码如下:
package com.seassoon;

import com.corundumstudio.socketio.*;
import com.corundumstudio.socketio.store.RedissonStoreFactory;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

public class SocketIOServerExample {
public static void main(String[] args) {
// 配置 Redisson 客户端
Config redissonConfig = new Config();
redissonConfig.useSingleServer()
.setAddress("redis://127.0.0.1:6379"); // 替换为你的 Redis 地址和端口
RedissonClient redisson = Redisson.create(redissonConfig);

    // 配置 Socket.IO 服务器
    Configuration config = new Configuration();
    config.setHostname("localhost");
    config.setPort(9092); // 选择一个适合你环境的端口
    config.setStoreFactory(new RedissonStoreFactory(redisson)); // 使用 Redisson 作为存储工厂

    final SocketIOServer server = new SocketIOServer(config);
    server.addConnectListener(client -> {
        System.out.println("Client connected: " + client.getSessionId());
    });

    server.addDisconnectListener(client -> {
        System.out.println("Client disconnected: " + client.getSessionId());
    });

    server.addEventListener("message", String.class, (client, data, ackSender) -> {
        System.out.println("Received message: " + data);
        server.getBroadcastOperations().sendEvent("message", data);
    });

    server.start();

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        server.stop();
        redisson.shutdown();
    }));
}

}
pom.xml依赖如下:
com.corundumstudio.socketio
netty-socketio

org.redisson
redisson
3.24.3

测试网页如下:
<title>Socket.IO Client</title> <script src="https://cdn.bootcss.com/socket.io/2.0.3/socket.io.js"></script> <script> document.addEventListener('DOMContentLoaded', function () { var socket = io('http://localhost:9092'); // 确保地址和端口与服务器匹配
        socket.on('connect', function () {
            console.log('Connected to the server');
            socket.emit('message', 'Hello from client!');
        });

        socket.on('message', function (data) {
            console.log('Received message:', data);
        });

        socket.on('disconnect', function () {
            console.log('Disconnected from the server');
        });
    });
</script>

Socket.IO Client

reids命令监控如下: C:\Users\steven>redis-cli 127.0.0.1:6379> monitor OK 1706330507.003321 [0 127.0.0.1:60677] "PUBLISH" "disconnect" "\x01\x00com.corundumstudio.socketio.store.pubsub.DisconnectMessag\xe5\x01\x8e\xfec\x01\xd4M=\x15T,\xa5f\x9d\xcd\x1ag\xae\x9c\xcd\xaa" 1706330507.005337 [0 127.0.0.1:60678] "PUBLISH" "leave" "\x01\x00com.corundumstudio.socketio.store.pubsub.JoinLeaveMessag\xe5\x81\x01\x8e\xfec\x81\x01\xd4M=\x15T,\xa5f\x9d\xcd\x1ag\xae\x9c\xcd\xaa" 1706330507.417483 [0 127.0.0.1:60679] "PUBLISH" "connect" "\x01\x00com.corundumstudio.socketio.store.pubsub.ConnectMessag\xe5\x01\x8e\xfec\x01x@V\x85\xa3U\xf8x\xb3x$\xf3\xd8\x9f \xbb" 1706330507.418449 [0 127.0.0.1:60680] "PUBLISH" "join" "\x01\x00com.corundumstudio.socketio.store.pubsub.JoinLeaveMessag\xe5\x81\x01\x8e\xfec\x81\x01x@V\x85\xa3U\xf8x\xb3x$\xf3\xd8\x9f \xbb" 1706330507.742422 [0 127.0.0.1:60681] "PUBLISH" "dispatch" "\x01\x00com.corundumstudio.socketio.store.pubsub.DispatchMessag\xe5\x81\x01\x8e\xfec\x01\x01com.corundumstudio.socketio.protocol.Packe\xf4\x00\x01\x02java.util.Collections$EmptyLis\xf4\x00\x01\x03java.util.Arrays$ArrayLis\xf4\x82\x03\x00Hello from client\xa1\x00\x02messag\xe5\x81\n\x05\x81" 1706330520.014406 [0 127.0.0.1:60666] "PING" 1706330520.014611 [0 127.0.0.1:60665] "PING" 1706330520.014745 [0 127.0.0.1:60667] "PING"

redis的KEY查询结果如下:

C:\Users\steven>redis-cli
127.0.0.1:6379> keys *
未查到任何记录
127.0.0.1:6379>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant