Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up my simple Redis .NET application

Tags:

c#

.net

linq

redis

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. (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:

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?

like image 664
Tys Avatar asked Feb 13 '26 00:02

Tys


1 Answers

I found this Documentation: https://github.com/ServiceStack/ServiceStack.Redis/wiki/IRedisClient But it' s not an Linq Provider.
I didn't find a way to get companies filtered, you can only get all or one by 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:

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

I'm not sure if you need the ToList call.

Hopefully someone gives you a better solution.

like image 52
Dannydust Avatar answered Feb 14 '26 14:02

Dannydust



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!