我目前在我的linux系统上测试过redis-benchmark,并且对结果印象深刻。但是在进行基准测试时,我使用了16条命令的流水线。现在,我试图在C#上执行它。
我的主要问题是我想将成千上万的随机数据记录到Redis中,但我不知道该如何使用流水线。
提前致谢。
最佳答案
在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
但是,请注意,如果没有这一点,您可以取得很多成就,因为:
CreateTransaction()
API,但没有严格要求)还请注意,在某些批量方案中,您可能还需要考虑使用Lua(
ScriptEvaluate()
);这个API是可变的,因此可以适应任意参数长度-您的Lua只需检查KEYS
和ARGV
(discussed in the EVAL
documentation)的大小。