0

我正在使用带有 redis 的 nodeJS 作为数据存储并且遇到了问题。我有一个 redis 频道设置,我的 HTML5 应用程序通过服务器发送事件订阅,但是当我从 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() 一些参数以使其执行换行吗?

在发布到频道之前,我确实尝试过替换换行符......但我宁愿将它们保留在那里以提高可读性;此外,那是针对症状而不是疾病。

谢谢!

4

1 回答 1

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

于 2012-12-17T11:17:01.183 回答