I'm a bit mixed up about the difference between a Redis transaction and pipeline and ultimately how to use pipelines with Booksleeve. I see that Booksleeve has support for the Redis transaction feature (MULTI
/EXEC
), but there is no mention in its API/tests about a pipelining feature. However, it's clear in other implementations that there is a distinction between pipelines and transactions, namely in atomicity, as evidenced in the redis-ruby version below, but in some places the terms seem to be used interchangeably.
redis-ruby implementation:
r.pipelined {
# these commands will be pipelined
r.get("insensitive_key")
}
r.multi {
# these commands will be executed atomically
r.set("sensitive_key")
}
I'd just use MULTI
/EXEC
instead but they seem to block all other users until the transaction has completed (not necessary in my case), so I worry about their performance. Has anyone used pipelines with Booksleeve or have any ideas about how to implement them?
In BookSleeve, everything is always pipelined. There are no synchronous operations. Not a single one. As such, every operation returns some form of Task
(could be a vanilla Task
, could be a Task<string>
, Task<long>
, etc), which at some point in the future (i.e. when redis responds) will have a value. You can use Wait
at your calling code to perform a synchronous wait, or ContinueWith
/ await
(C# 5 language feature) to perform an asynchronous callback.
Transactions are no different; they are pipelined. The only subtle change with transactions is that they are additionally buffered at the call-site until complete (since it is a multiplexer, we can't start pipelining transaction-related messages until we have a complete unit-of-work, as it would adversely impact other callers on the same multiplexer).
So: the reason there is no explicit .pipelined
is that everything is pipelined and asynchronous.