Currently I am storing the actual socket object in an array in each process. I then store socket data in redis for all processes (workers) to access.
Is there a more performance/efficient way to store and retrieve sockets, or is this pretty much how this is done? I am concerned about performance when the sockets array potentially grows to over 200k objects.
var _ = require('underscore');
//Storing the socket in memory and saving the redis associated data
var server = this;
//This function adds this hash to redis and returns a unique id
server.gs.addSocketInfo({
"userid": 0,
"displayName": "Mike's iPhone",
"connecttime": new Date().getTime()
}, function(err, socketid) {
socket.socketid = socketid;
server.sockets.push(socket);
doReady();
});
//To retrieve the data and socket later
//function returns the socket data from redis
server.gs.getSocketInfo(socket.socketid, function(err, sinfo) {
var socket = _.find(server.sockets, function(socket) {
return socket.socketid === sinfo.socketid;
});
if (socket)
//Do something with the socket here...
});