这是我的互动会话。它很棒。
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
1) testkey
ec2-54-83-60-31.compute-1.amazonaws.com:11729> flushall
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
ec2-54-83-60-31.compute-1.amazonaws.com:11729> watch testkey
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> multi
OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> set testkey testvalue
QUEUED
ec2-54-83-60-31.compute-1.amazonaws.com:11729> exec
1) OK
ec2-54-83-60-31.compute-1.amazonaws.com:11729> keys *
1) testkey
ec2-54-83-60-31.compute-1.amazonaws.com:11729> get testkey
testvalue
ec2-54-83-60-31.compute-1.amazonaws.com:11729>
这是我的代码,以及执行它的方式。
var redis = require('redis');
var rdsclt = redis.createClient(process.env.REDIS_URL);
console.log('Before test block.');
console.log('rdsclt.flushall();');
rdsclt.flushall();
console.log('rdsclt.watch(\'testkey\');');
rdsclt.watch('testkey');
console.log('rdsclt.multi();');
rdsclt.multi();
console.log('rdsclt.set(\'testkey\', \'testvalue\');');
rdsclt.set('testkey', 'testvalue');
console.log('rdsclt.exec( (error, results) => {');
rdsclt.exec( (error, results) => {
console.log('Inside test block exec callback.');
console.log('error =', JSON.stringify(error) );
console.log('results =', JSON.stringify(results) );
});
console.log('After test block.');
return 0; // Hopefully, indicates success, in Unix.
2016-11-07T19:39:20.038712+00:00 heroku[web.1]: Starting process with command `npm start`
2016-11-07T19:39:22.685896+00:00 app[web.1]:
2016-11-07T19:39:22.685912+00:00 app[web.1]: > cubsredistest@1.0.0 start /app
2016-11-07T19:39:22.685913+00:00 app[web.1]: > node main.js
2016-11-07T19:39:22.685914+00:00 app[web.1]:
2016-11-07T19:39:22.918869+00:00 app[web.1]: Before test block.
2016-11-07T19:39:22.919519+00:00 app[web.1]: rdsclt.flushall();
2016-11-07T19:39:22.920435+00:00 app[web.1]: rdsclt.watch('testkey');
2016-11-07T19:39:22.920662+00:00 app[web.1]: rdsclt.multi();
2016-11-07T19:39:22.920903+00:00 app[web.1]: rdsclt.set('testkey', 'testvalue');
2016-11-07T19:39:22.920959+00:00 app[web.1]: rdsclt.exec( (error, results) => {
2016-11-07T19:39:22.921021+00:00 app[web.1]: After test block.
2016-11-07T19:39:22.937915+00:00 app[web.1]: Inside test block exec callback.
2016-11-07T19:39:22.938011+00:00 app[web.1]: error = {"command":"EXEC","code":"ERR"}
2016-11-07T19:39:22.938287+00:00 app[web.1]: results = undefined
2016-11-07T19:39:00+00:00 app[heroku-redis]: source=REDIS sample#active-connections=1 sample#load-avg-1m=0.09 sample#load-avg-5m=0.13 sample#load-avg-15m=0.1 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664468.0kB sample#memory-free=13536884.0kB sample#memory-cached=694560kB sample#memory-redis=289016bytes sample#hit-rate=1 sample#evicted-keys=0
我会说这两个应该产生相同的结果,但他们没有。我正在使用使用npm install redis
安装的redis客户端。我知道还有其他客户。
有人知道发生了什么吗?
我将节点客户端从node_redis更改为ioredis。
已从npm install redis
更改为npm install ioredis
。
现在,错误消息提供了更多信息。
2016-11-07T20:28:02.704282+00:00 app[web.1]: Inside test block exec callback.
2016-11-07T20:28:02.704615+00:00 app[web.1]: error = {"name":"ReplyError","message":"ERR EXEC without MULTI","command":{"name":"exec","args":[]}}
2016-11-07T20:28:02.704620+00:00 app[web.1]: results = undefined
2016-11-07T20:27:43+00:00 app[heroku-redis]: source=REDIS sample#active-connecti
还没有解决问题。
答案 0 :(得分:0)
Arghh! node_redis'测试的一个例子是:
it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.WATCH(watched);
client.incr(watched);
var multi = client.multi();
multi.incr(watched);
multi.exec(helper.isNull(done));
});
我在做的是:
it('does not execute transaction if watched key was modified prior to execution', function (done) {
client.WATCH(watched);
client.incr(watched);
client.multi();
client.incr(watched);
client.exec(helper.isNull(done));
});
我会把它留在这里。也许它会帮助下一个人。