-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
multi
is not supported with autopipelining, meaning that each execution is its own network request. I have a consumer which reads logs, aggregates, increments a key and then sets an expirary (TTL). Obviously the less number of network requess I make the less there is to do overall, and so I can process more.
The reason I'm using multi in the first place is because of the two coupled operations; (1) incrementing the key and (2) setting the TTL. What we have is something like this.
const transaction = redis.multi();
transaction.hincrby('bucket', 'count', 1);
transaction.expireat('bucket', 1000);
await transaction.exec();
My thinking in coupling these is that, I want to make sure that the bucket exists before setting the TTL; I don't want to there to be orphan "buckets".
So heres to my question, if autopipelining is enabled, is the order of execution guarunteeed?
Lets say if we do away with transactions and just have
const results = await Promise.all([
redis.hincrby('bucket', 'count', 1),
redis.expireat('bucket', 1000)
]);
would these commands always be queued in this order, in the same way an explicit pipeline was created with them both, would these be always executed in the same batch as well?
Lastly is this the best way of doing this, would this be a case where we need to lean more on Lua to couple these commands?
Thanks 🙏