是否可以在nodejs中存储循环引用对象?
我想在所有服务器上扩展我的传入请求。
我可以在集群中声明全局变量,将所有传入请求存储在数组中。
//SERVER 1
var store =[];
//Instance node master
http.createServer(function(req,res){
store['InRequest1']=req;
});
//Instance node child
http.createServer(function(req,res){
var request = store['InRequest1'];
request.write('sss');
});
但是,如果我在另一台服务器上创建另一个实例,我无法取回存储请求:
//SERVER 2
var request = store['InRequest1'];
request.write('sss');
我找到了使用 memcached/redis 存储循环对象(请求)的方法,但是当我尝试
memcached.set(req); //hit error unable convert circular reference objects
缩放循环引用对象时?
I want to scale my incoming request cross all servers.
I can done in cluster with declare global variable store all incoming request in array.
//SERVER 1
var store =[];
//Instance node master
http.createServer(function(req,res){
store['InRequest1']=req;
});
//Instance node child
http.createServer(function(req,res){
var request = store['InRequest1'];
request.write('sss');
});
But if i create another instance on another server, i was unable get back the store request :
//SERVER 2
var request = store['InRequest1'];
request.write('sss');
I found the way to use memcached/redis to store the circular objects (request) but when i try to
memcached.set(req); //hit error unable convert circular reference objects
Got anyway to scale the circular reference object ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
呃什么?除非您在服务器之间同步它们,否则这是行不通的。我换个方式来说:猜猜我现在正在想的数字! (提示:你显然不能)
你的方法的后半部分是正确的方法。使用数据库来跟踪所有服务器上的数据。但每次继续之前,您都必须检查数据库。最终,由于延迟,这会导致一些问题。
我不明白这部分。你能详细说明一下吗?什么循环引用?
Uh what? Unless you synchronize them across the servers, that cannot work. I'll put it another way: Guess the number I'm thinking right now! (hint: you obviously can't)
The latter half of your approach is the right way to go. Use a database to keep track of the data across all the servers. But you're going to have to check with the database before continuing everytime. This will lead to some problems, eventually, due to latency.
I don't understand this part. Can you elaborate? What circular reference?