小编Cha*_*ort的帖子

用于node.js中聊天服务器的Redis pub/sub

我正在尝试使用Redis Cookbook示例:

var http = require('http'),
io = require('socket.io')
fs = require('fs'),
redis = require('redis'),
rc = redis.createClient(9189, "pike.redistogo.com");
rc.auth("passwd", function() {
    console.log("Connected! to redistogo!");});

rc.on("connect", function() {
    rc.subscribe("chat");
    console.log("rc connect event");
});
Run Code Online (Sandbox Code Playgroud)

我在这里取得了成功但从未得到"消息".

rc.on("message", function (channel, message) {
 console.log("Sending: " + message);
 socketio.sockets.emit('message', message);
});

webpage = http.createServer(function(req, res){
console.log('webpage request starting...');

fs.readFile('./index.htm', function(error, content) {
    if (error) {
        res.writeHead(500);
        res.end();
    }
    else {
        res.writeHead(200, { 'Content-Type': 'text/html' });
        res.end(content, 'utf-8');
     }
 });
 });

 webpage.listen(7777);
Run Code Online (Sandbox Code Playgroud)

我的客户端index.htm就是这个

<!docttype html>
<html …
Run Code Online (Sandbox Code Playgroud)

redis node.js socket.io

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

node.js ×1

redis ×1

socket.io ×1