关于socket.io 负载均衡问题,参考官网Using multiple nodes:http://socket.io/docs/using-multiple-nodes/, 我设置如下:
var io = require('socket.io').listen(8891);
var port=6379;
var host='localhost';
var pwd = '******';
var redis = require('redis').createClient;
var adapter = require('socket.io-redis');
var pub = redis(port, host, { auth_pass: pwd });
var sub = redis(port, host, { detect_buffers: true, auth_pass: pwd });
io.adapter(adapter({ pubClient: pub, subClient: sub }));
关于这个adapter
总是报错:
io.adapter(adapter({ pubClient: pub, subClient: sub }));
^
TypeError: undefined is not a function
at Object.<anonymous> (/home/team/project/ylx/sync-svc/sync-server_8891.js:18:4)
at Module._compile (module.js:462:26)
at Object.Module._extensions..js (module.js:480:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:503:10)
at startup (node.js:132:16)
at node.js:817:3
我的socket.io版本0.9.17,其他版本见下方:
├─┬ hiredis@0.3.0
│ ├── bindings@1.2.1
│ └── nan@1.5.3
├── redis@0.12.1
├─┬ socket.io@0.9.17
│ ├── base64id@0.1.0
│ ├── policyfile@0.0.4
│ ├── redis@0.7.3
│ └─┬ socket.io-client@0.9.16
│ ├─┬ active-x-obfuscator@0.0.1
│ │ └── zeparser@0.0.5
│ ├── uglify-js@1.2.5
│ ├─┬ ws@0.4.32
│ │ ├── commander@2.1.0
│ │ ├── nan@1.0.0
│ │ ├── options@0.0.6
│ │ └── tinycolor@0.0.1
│ └── xmlhttprequest@1.4.2
└─┬ socket.io-redis@0.1.4
├── debug@0.7.4
├─┬ msgpack-js@0.3.0
│ └─┬ bops@0.0.7
│ ├── base64-js@0.0.2
│ └── to-utf8@0.0.1
├── redis@0.10.1
├─┬ socket.io-adapter@0.3.1
│ ├─┬ debug@1.0.2
│ │ └── ms@0.6.2
│ ├── object-keys@1.0.1
│ └─┬ socket.io-parser@2.2.2
│ ├── benchmark@1.0.0
│ ├── component-emitter@1.1.2
│ ├── debug@0.7.4
│ ├── isarray@0.0.1
│ └── json3@3.2.6
└── uid2@0.0.3
对于此类问题求解决方案~
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.