c# - servicestack.redis GetAll().where() 和 GetByIds() 之间有速度差异吗

标签 c# .net redis servicestack

最近在用servicestack.redis,需要从IRedisTypedClient查询.我知道所有数据都在内存中,但仍然想知道 GetAll().Where() 之间的速度是否不同?和 GetByIds()

GetAll()GetByIds()是servicestack.redis提供的两个方法。

使用 GetAll()可以继续在结果中搜索(通过 lambda),这意味着我可以使用一些自定义条件,但我不知道,这是否会从 redis 内存中加载所有数据,然后在 IEnumable<T> 中搜索, 搜索速度会不会比GetByIds()慢.

最佳答案

我刚刚做了一个实验,我存储了100万个对象(ps:servicestack有一个bug,一次​​只能存储大约50万个对象)。

用这两种方法查询。

DateTime beginDate = DateTime.Now;
Debug.WriteLine("查询1开始");`  
Website site = WebsiteRedis.GetByCondition(w => w.Name == "网址2336677").First();
double time = (DateTime.Now - beginDate).TotalMilliseconds;
Debug.WriteLine("耗时:" + time + "ms");

DateTime beginDate2 = DateTime.Now;
Debug.WriteLine("查询2开始");
Website site2 = WebsiteRedis.GetByID(new Guid("29284415-5de0-4781-bea4-5e01332814b2"));
double time2 = (DateTime.Now - beginDate2).TotalMilliseconds;
Debug.WriteLine("耗时:" + time2 + "ms");

结果是
GetAll().Where() - 需要 19 秒,
GetById()- 需要 190 毫秒。

我猜是因为 servicestack 使用对象 id 作为 redis 的键,所以永远不要使用 GetAll().Where() 作为查询,每个对象应与 id 相关并使用 GetById() 作为查询。 GetAll() 应在记录较少的对象上使用。

关于c# - servicestack.redis GetAll().where() 和 GetByIds() 之间有速度差异吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38970305/

相关文章:

django - 导入 asgi_redis : ImportError: No module named _compat

c# - 我如何优化此 linq 函数以计算 "OrePreviste"的总和?

c# - silverlight 3.0与winforms的通信

.net - 字符串的 GetHashCode() 方法可以返回零吗?

c# - Xamarin 表单更新 listView itemSsource

c# - 为什么没有 .NET 的 CPAN?

redis - 获得更快的 redis 故障转移

python - 终止挂起的 redis pubsub.listen() 线程

c# - 使用 LinqDataSource 格式化问题的下拉列表

c# - 流不可写