How do I serialize `DefaultWebSocketServerSession`...
# ktor
a
How do I serialize
DefaultWebSocketServerSession
?
d
What’s your use case? What are you trying to achieve?
a
store it in redis
d
But that session is a wrapped socket connection, that won’t exists later. You cannot serialize a socket
what you can do is to serialize a state that you associate to that session
you can use jackson or gson to serialize/deserialize a simple data class with your state, but not with a socket
a
If I have ktor on multiple instances, how do I share websocket sessions?
d
usually you have a session, you can store it on redis if you want
Here there is a proposal for redis sessions: https://github.com/ktorio/ktor/pull/504/files You can copy the code and use the redis client you are using for it
As long as the client has the same session-id, if it reconnects to another server, that redis-backed session should work
if you want the state to be associated to the user instead to a session
you can use raw redis to do that
for example:
hset("props-$userId", "property", "value")