简体   繁体   English

加速我的简单Redis .NET应用程序

[英]Speeding up my simple Redis .NET application

I have started writing an application which i want to use for fast searching through my data. 我已经开始编写一个应用程序,我想用它来快速搜索我的数据。

I started using the client from ServiceStack.Redis. 我开始使用ServiceStack.Redis中的客户端。 (Got it via NuGet) Around this i wrote a little test app to insert 20k of company data records and now i'm querying this thing using the following code: (通过NuGet得到)围绕这个我写了一个小测试应用程序来插入20k的公司数据记录,现在我使用以下代码查询这个东西:

using (var companies = redisClient.As<Company>())
{
  var companiesFound = companies.GetAll().Where(x => x.CompanyName.Contains(searchString));
  dgvOutput.DataSource = companiesFound.ToList<Company>();
}

The Company class i use looks like this: 我使用的公司类看起来像这样:

public class Company
{
  public long Id { get; set; }
  public string CompanyName { get; set; }
  public string CompanyAddress { get; set; }
  public string CompanyCity { get; set; }
}

This all works well, but i can't say that it's fast. 这一切都运作良好,但我不能说它很快。 Can anyone help me on what to do to get this thing running as fast as it can be? 任何人都可以帮我做什么来让这个东西尽可能快地运行? Indexes? 指标? Different type of queries? 不同类型的查询? Better not use LINQ? 最好不要使用LINQ?

I found this Documentation: https://github.com/ServiceStack/ServiceStack.Redis/wiki/IRedisClient But it' s not an Linq Provider. 我找到了这个文档: https//github.com/ServiceStack/ServiceStack.Redis/wiki/IRedisClient但它不是Linq Provider。
I didn't find a way to get companies filtered, you can only get all or one by Id. 我找不到让公司过滤的方法,你只能通过Id获得全部或一个。

So I think, in the beginning, you have to get all Companies. 所以我认为,一开始,你必须得到所有公司。 And store it in application cache, maybe on Startup of your application 并将其存储在应用程序缓存中,可能是在应用程序的启动时

companies =  redisClient.As<Company>().GetAll();

and then you can filter the List with Linq2Objects like you did before: 然后你可以像之前那样使用Linq2Object过滤List:

var companiesFound = companies.Where(x => x.CompanyName.Contains(searchString));
  dgvOutput.DataSource = companiesFound;

I'm not sure if you need the ToList call. 我不确定你是否需要ToList调用。

Hopefully someone gives you a better solution. 希望有人能为您提供更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM