[英]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.我目前已经在我的 linux 系统上测试了 redis-benchmark,结果给我留下了深刻的印象。 But while benchmarking, I used pipelining of 16 commands.
但是在进行基准测试时,我使用了 16 个命令的流水线。 Now I am trying to execute it on c#.
现在我试图在 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.
我的主要问题是我想将数千个随机数据记录到 redis 中,但我不知道如何使用流水线。
Thanks in advance.提前致谢。
The most explicit way to use pipelining in StackExchange.Redis is to use the CreateBatch
API:在 StackExchange.Redis 中使用流水线的最明确方法是使用
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:但是,请注意,如果没有它,您可以取得很多成就,因为:
CreateTransaction()
API)CreateTransaction()
API,但没有那么严格) Note also that in some bulk scenarios you might also want to consider Lua ( ScriptEvaluate()
);另请注意,在某些批量场景中,您可能还需要考虑 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 ).这个 API 是可变的,因此可以适应任意参数长度 - 您的 Lua 只需要检查
KEYS
和ARGV
的大小(在EVAL
文档中讨论)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.