0
這是我的互動會話。它效果很好。以交互方式進行操作並且它可以正常工作。以編程方式執行相同的操作,並且失敗。 Redis,heroku,節點
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]: > [email protected] 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
還沒有解決問題。