我正在通过redis将storm连接到javascript。redis部分工作得很好,但是当我尝试发布元组(真正的字符串)时,我的代码(来自internet的一个例子只是稍微修改了一下)没有收到任何东西,redis也能很好地接收元组。这是我的密码:
/*
Node.js server script
Required node packages: express, redis, socket.io
* /
const PORT = 3000;
const HOST = 'localhost';
var express = require('express'),
http = require('http'),
server = http.createServer(app);
log('info', 'connected to express');
var app = express();
const redis = require('redis');
const client = redis.createClient();
log('info', 'connected to redis server');
const io = require('socket.io');
if (!module.parent) {
server.listen(PORT, HOST);
const socket = io.listen(server);
socket.on('connection', function(client) {
const subscribe = redis.createClient()
subscribe.subscribe('realtime');
subscribe.on("message", function(channel, message) {
client.send(message);
log('msg', "received from channel #" + channel + " : " + message);
});
client.on('message', function(msg) {
log('debug', msg);
});
client.on('disconnect', function() {
log('warn', 'disconnecting from redis');
subscribe.quit();
});
});
}
function log(type, msg) {
var color = '\u001b[0m',
reset = '\u001b[0m';
switch(type) {
case "info":
color = '\u001b[36m';
break;
case "warn":
color = '\u001b[33m';
break;
case "error":
color = '\u001b[31m';
break;
case "msg":
color = '\u001b[34m';
break;
default:
color = '\u001b[0m'
}
console.log(color + ' ' + type + ' - ' + reset + msg);
}
当我发送int时,它会将消息发送到终端,但不是用元组。我只是一个javascript迷,我不明白为什么它不能像int一样读取元组。
提前谢谢
1条答案
按热度按时间ve7v8dk21#
当我在redis的treatmen中发送消息时,它们在哪里被拆分,现在没有,消息到达客户机。
谢谢你的回答!