Answer the question
In order to leave comments, you need to log in
Is it possible to store node.js objects in Redis?
Hello.
I am writing a TCP server on node.js. There can be many clients and they send messages every 5-10 seconds. For starters, I just made a hash of the sockets (clients) by their ID. But, as I said, there can be many clients, and keeping it all in the memory of the node is expensive, I think so.
I thought about Redis. But as I remember, Redis saves everything as a string. Is it possible to use serialization to JSON and vice versa? Do they do that at all?
Is it even possible to store these sockets (native node objects with methods and others) in Redis or in some NoSQL storage?
Answer the question
In order to leave comments, you need to log in
No. You need to process them, they are open TCP sockets, to which database? Each socket has an identifier and a piece of memory is allocated at the operating system level for a buffer. In addition, something comes from each socket, and something needs to be sent to it, is that also what to do through the base? It looks like you need to read about TCP / IP, about sockets and about network programming at least a few articles, at least on Habré. And you need a cluster to distribute these sockets to several processes, so that one really does not run out of memory and to occupy other processor cores.
Also, note that TCP is not a packet oriented protocol, but a streaming one, i.e. if you send 10kb of data at one time, then they can come in one time, or they can be detailed as you like, come in 4 times, for example, 1kb + 3kb + 4kb + 2kb. They can also stick together, if you send 5 fragments in a row, they can stick together into one. Moreover, a small part can peel off from one parcel and stick to the next. All TCP guarantees is that the data arrives accurately and in the correct sequence.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question