6
2つのクライアントを作成しようとしています。 1つはpub/sub、もう1つは標準接続です。これは不可能ですか?基本的に、test.jsの実行後にget key
を実行すると、私が見るのはすべて「valueBefore」です。出力:Redis/Node.js - 書き込みで問題を引き起こす2クライアント(1 pub/sub)
node test.js
Reply: OK
/Users/franklovecchio/Desktop/development/node/node_modules/redis/index.js:487
throw new Error("Connection in pub/sub mode, only pub/sub commands may
^
Error: Connection in pub/sub mode, only pub/sub commands may be used
at RedisClient.send_command (/Users/franklovecchio/Desktop/development/node/node_modules/redis/index.js:487:15)
at RedisClient.<anonymous> (/Users/franklovecchio/Desktop/development/node/node_modules/redis/index.js:597:27)
at Object._onTimeout (/Users/franklovecchio/Desktop/development/node/distributed-cache/client/test.js:19:12)
at Timer.callback (timers.js:83:39)
コード:client2
は、特定のチャネル上のメッセージをリッスンに専用されているので、
var redis = require('redis');
var client1 = redis.createClient();
var client2 = redis.createClient();
client2.on('message', function (channel, message) {
console.log('Received a message on channel: ' + channel);
client1.set('key', message, redis.print);
});
client2.subscribe('channel');
client1.set('key', 'valueBefore', redis.print);
setTimeout(
function() {
client2.publish('channel', 'valueAfter');
},3000
);