-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Order of received commands #91
Comments
Typically if you want to make sure the execution order of commands, you should either using pipelining or invoking another command after the previous command returning. For instance: redis.pipeline().multi().del('foo').del('bar').exec().get('foo').exec(); Or redis.multi().del('foo').del('bar').exec(function () {
redis.get('foo');
}); This is because although almost all simple commands are sent to the redis server follow the exactly same order they invoked, there are still some exceptions. For example when invoking a custom lua command: redis.echo();
redis.get('foo'); ioredis first sends When it comes to |
I understand, thanks for the explanation. emitter.on('foo', function () {
redis.multi().del('bar').del('baz').exec();
});
emitter.on('foo', function () {
redis.get.('bar', function (err, res) {
if (res) console.log('(屮ಠ益ಠ)屮 Y U STILL HERE');
});
}); and the two listerners can't be merged because the second one is attached later. A workaround for this particular case is to call |
I'm going to try to change this behaviour at this weekend to make BTW just some random workarounds: emitter.on('foo', function () {
redis.multi().del('bar').del('baz').exec();
});
emitter.on('foo', function () {
setImmediate(function () {
redis.get.('bar', function (err, res) {
if (res) console.log('(屮ಠ益ಠ)屮 Y U STILL HERE');
});
});
}); emitter.on('foo', function () {
redis.multi().del('bar').del('baz').exec(function () {
emitter.emit('after foo');
});
});
emitter.on('after foo', function () {
redis.get.('bar', function (err, res) {
if (res) console.log('(屮ಠ益ಠ)屮 Y U STILL HERE');
});
}); emitter.on('foo', function () {
redis.multi({ pipeline: false });
redis.del('bar');
redis.del('baz');
redis.exec();
});
emitter.on('foo', function () {
redis.get.('bar', function (err, res) {
if (res) console.log('(屮ಠ益ಠ)屮 Y U STILL HERE');
});
}); |
The last example with 'use strict';
var Redis = require('ioredis')
, redis = new Redis();
redis.multi({ pipeline: false });
redis.del('foo');
redis.del('bar');
redis.exec();
|
Fixed in 1.5.11. 😄 |
👍 |
When using
multi
orpipeline
the order of the commands received by the server is not the expected one:With
node_redis
the same code executes the commands in the expected order:Is this wanted?
The text was updated successfully, but these errors were encountered: