Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use redis pipiline(StackExchange.Redis) in c#?

I have currently tested redis-benchmark on my linux system and was impressed by the results. But while benchmarking, I used pipelining of 16 commands. Now I am trying to execute it on c#. My main problem is I want to log some thousands of random data into redis and I can't figure how to used pipelining with this.

Thanks in advance.

like image 749
anand kumar Panigrahi Avatar asked Oct 19 '25 15:10

anand kumar Panigrahi


1 Answers

The most explicit way to use pipelining in StackExchange.Redis is to use the CreateBatch API:

var db = conn.GetDatabase();
var batch = db.CreateBatch();
// not shown: queue some async operations **without** awaiting them (yet)
batch.Execute(); // this sends the queued commands
// now await the things you queued

however, note that you can achieve a lot without that, since:

  • concurrent load from different threads (whether sync or async) is multiplexed, allowing effective sharing of a single connection
  • the same trick of "issue multiple async operations but don't await them just yet" still works fine even without the batch API (using the batch API ensures that the batch is sent as a contiguous block without work from concurrent threads getting interleaved within the batch; this is similar to, but less strict than, the CreateTransaction() API)

Note also that in some bulk scenarios you might also want to consider Lua (ScriptEvaluate()); this API is varadic, so can adapt to arbitrary argument lengths - your Lua simply needs to inspect the sizes of KEYS and ARGV (discussed in the EVAL documentation).

like image 75
Marc Gravell Avatar answered Oct 22 '25 05:10

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!