我目前在我的 linux 系统上测试了 redis-benchmark,结果给我留下了深刻的印象。但是在进行基准测试时,我使用了 16 个命令的流水线。现在我正在尝试在 c# 上执行它。
我的主要问题是我想将数千个随机数据记录到 redis 中,但我不知道如何使用流水线。
提前致谢。
最佳答案
在 StackExchange.Redis 中使用流水线的最明确方式是使用 CreateBatch
接口(interface):
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)。
关于c# - 如何在 C# 中使用 redis pipiline(StackExchange.Redis)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61117360/