我有一个似乎运行良好的NodeJS应用程序。在顶部:
var redis = require('node-redis');
然后我从第三方提要中获取一些数据,将他们的XML转换为我们的JSON,然后我:
for (var i=0; i < books.length; i++) {
var book = books[i];
// Add a job to redis
redisClient.publish("edison-nye", JSON.stringify(book));
}
一切似乎都很棒。如果我登录Redis并运行MONITOR命令,我可以看到所有正在写入的数据。
但后来我创建了第二个NodeJS应用程序。这将订阅第一个应用程序发布到的频道。
所以第二个应用程序:
var redis = require('node-redis');
var redisClient = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST, process.env.REDIS_PASSWORD);
redisClient.subscribe("edison-nye");
现在我开始看到这样的错误:
[Error: winning journalist and the publisher of Bloomberg View. He has worked at the <I>New York Times</I>, the <I>Wall Street Journal</I>, <I>Talk </I>magazine, and the <I>Huffington Post</I>. O’Brien edited a Pulitzer Prize–winning series on wounded war veterans in 2012 and is a recipient of the Gerald Loeb Award for Distinguished Business a
更多。
和
[SyntaxError: Unexpected token e]
当我查看写入Redis的原始数据时,我看到:
\"authorbiocontact\":[\"<div>Timothy L. O’Brien is an award-winning journalist and the publisher of Bloomberg View. He has worked at the <I>New York Times</I>, the <I>Wall Street Journal</I>, <I>Talk </I>magazine, and the <I>Huffington Post</I>.
所以这个连字符是问题所在:
award-winning
还有其他几十个例子。
那么当我把连字符写入Redis时,我怎么想处理连字符呢?
[[更新]]
堆栈跟踪:
at EventEmitter.<anonymous> (/Users/hasan/projects/ingestion_workers/node_modules/node-redis/index.js:227:13)
at emitOne (events.js:90:13)
at EventEmitter.emit (events.js:182:7)
at EventEmitter.onError (/Users/hasan/projects/ingestion_workers/node_modules/node-redis/parser.js:365:10)
at EventEmitter.onIncoming (/Users/hasan/projects/ingestion_workers/node_modules/node-redis/parser.js:130:16)
at Socket.<anonymous> (/Users/hasan/projects/ingestion_workers/node_modules/node-redis/index.js:98:19)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:529:20)
[[更新]] [[更新]]
有趣!并非所有人都在大肆宣传。我发表了这个:
This fixed-layout ebook, which preserves the design and layout of the original print book, features read-along narration
我得到了回复:
[Error: layout ebook, which preserves the design and layout of the original print book, features read-along narration.
所以第一个连字符断了,但不是第二个连字符。