目前我将实际的套接字对象存储在每个进程的数组中。然后,我将套接字数据存储在redis中,供所有进程(工作人员)访问。
是否有更高性能/更高效的方式来存储和检索套接字,或者这是如何完成的?当套接字数组可能增长到超过200k的对象时,我担心性能。
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...
});