Playing with nodejs, socket.io and redis transaction.
Wondering what would happen with this code (dummy code)
var redis = require('redis');
var client = redis.createClient();
...
socket.on('setSomeKey', function() {
client.watch('someKey');
client.get('someKey',function(err,replies) {
client.multi().set('someKey','someValue').exec();
});
});
socket.on('setSomeStuff', function() {
client.watch('someStuff');
client.set('someStuff','blip');
...
});
Client 1 sends event 'setSomeKey':
-> redis watch someKey
-> redis get someKey and wait for reply
Client 2 sends event 'setSomeStuff'
-> redis watch someStuff
-> redis set someStuff & wait for reply
Client 1:
-> receives 'someKey' and try multi..exec:
=> will the watch on 'someStuff' set by client2 impact the multi exec ?
In other words, could this happens while watching redis with MONITOR:
- watch someKey
- get someKey
- watch someStuff
- set someStuff
- multi
- exec => FAIL because of "watch someStuff" which has change between get and multi..exec executed in the callback ?