nodejs无法将新行发布到redis

时间:2012-12-17 10:45:02

标签: node.js redis newline

我正在使用带有redis的nodeJS作为数据存储,并且遇到了问题。我有一个redis频道设置,我的HTML5应用程序通过Server Sent Events订阅,但是当我从nodejs服务器向频道发布一些包含换行符的文本时,只有第一行是由客户端获取的。

我是nodeJS / redis的新手,所以我很可能只是在做一些愚蠢的事情。这里很难复制所有代码,但总之,我正在做一些有效的事情:

// in the nodejs setup & controller
client = redis.createClient();
msg = "This is a test.\n\nAnd this is another.";
client.publish("mychannel", msg);

// on the client side javascript file
source = new EventSource('/main/stream')
source.addEventListener('mychannel', function(e) {
    $('#messages').append(e.data);
}, false);

我在#messages div中看到的是“这是一个测试”,但从来没有“这是另一个”。是否有一些参数我必须给publish()以使它做换行?

我确实在发布到频道之前尝试更换换行符...但我宁愿将它们留在那里以便于阅读;此外,这是攻击症状而不是疾病。

谢谢!

1 个答案:

答案 0 :(得分:0)

也许值得一试:

var nl = '\n'.charCodeAt(0);

msg = "This is a test."+nl+nl+"And this is another.";

如此处所见http://hermanjunge.com/post/10634913617/redis-nodejs-dump-txt-into-db