目前,我将实际的套接字对象存储在每个进程的数组中。然后,我将套接字数据存储在 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...
});