我想创建一个phantomjs脚本,它作为消费者进程从redis服务器读取值而启动。我看到节点(https://github.com/NodeRedis/node_redis)存在此客户端,我连接,写入和读取时没有问题执行节点脚本。
var redis = require("redis"),
client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print);
client.get("string key", redis.print);
但是当我对phantomjs做同样的事情时,我得到了这个错误:
ReferenceError: Can't find variable: process
phantomjs://platform/command.js:4
TypeError: undefined is not a constructor (evaluating 'util.inherits(assert.AssertionError, Error)')
phantomjs://platform/assert.js:161
TypeError: undefined is not a constructor (evaluating 'util.inherits(RedisError, Error)')
phantomjs://platform/redisError.js:17
TypeError: undefined is not a constructor (evaluating 'util.inherits(ReplyError, RedisError)')
phantomjs://platform/replyError.js:16
TypeError: undefined is not a constructor (evaluating 'util.inherits(ParserError, RedisError)')
phantomjs://platform/parserError.js:18
ReferenceError: Can't find variable: Buffer
phantomjs://platform/parser.js:22 in bufferAlloc
phantomjs://platform/parser.js:8
TypeError: undefined is not a constructor (evaluating 'util.inherits(AbortError, RedisError)')
phantomjs://platform/customErrors.js:43
Error: Cannot find module 'events'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
有没有办法将这个包与phantomjs一起使用?
答案 0 :(得分:1)
PhantomJS与node.js不兼容,您无法在其中使用此软件包。
最好的办法是为PhantomJS使用一些node.js网桥,例如https://github.com/amir20/phantomjs-node或https://github.com/baudehlo/node-phantom-simple,然后在该node.js脚本中使用node_redis。