如何在phantomjs脚本中使用“node_redis”?

我想制作一个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来使用这个包吗?

PhantomJS与node.js不兼容,您不能在其中使用此软件包。

最好的办法是为PhantomJS使用一些node.js桥接,比如https://github.com/amir20/phantomjs-node或https://github.com/baudehlo/node-phantom-simple ,然后在那里使用node_redis node.js脚本。