Reputation: 907
I'm currently learning node.js by developing a small chat application over TCP (classic case).
What I would like to do now is to extend this application to use static users:
I have looked into Redis to store this data but not been successful so far.
tcpServer.on 'connection', (tcpSocket) -> tcpSocket.write "Welcome"
redis.hmset("sessions", userid, tcpSocket)
tcpSocket.on "data", (data) ->
redis.hvals "sessions", (err, repl) ->
repl.forEach (reply, y) ->
reply.Write("Data is written to clients!")
tcpServer.listen 7000
Current error message: TypeError: Object [object Object] has no method 'write'
This indicates that I cannot store a tcpSocket as I'm trying to do right now. Can someone tell me if I can make minor adjustments to make this right or should I rethinkt this solution?
Upvotes: 0
Views: 1364
Reputation: 907
Since socket objects are to complex to store in Redis it seems like the way to go is to add identifier to the object according to link below.
This identifier could then of course be saved in a database to create realtions between different objects etc.
How to uniquely identify a socket with Node.js
Upvotes: 1
Reputation: 5841
Redis supports very few data types: string, lists, sets, sorted lists and hash tables. That's it. Some other types, like Date, can be easily converted to/from string, so it can be used too. But socket is a complex internal object, so you most probably can't convert it into string and therefore can't store in Redis.
Upvotes: 2