0

I am relatively new to NoSQL and am working on a project with Redis at back-end to a C# ASP.NET application. I am using ServiceStack.Redis as my C# client.

While CRUD is relatively simple, I wanted to know the fastest way of querying data from Redis. We have a list that can grow well beyond 200k records in a matter of days (since data for every second is recorded for various entities). Basically it's sensor data so if we are recording 200 attributes, then: 86400(s) x 200 = 172800 records per day.

My class looks as follows:

public class Snsr_Data_Val
{
    public long Snsr_ID { get; set; }
    public DateTime Rec_Date { get; set; }
    public long Category_ID { get; set; }
    public double Value {get; set; }
}

Currently my query looks like this

public IList<Snsr_Data_Val> GetDataForCategory(long category_id)
{
    PooledRedisClientManager redisManager = new PooledRedisClientManager("localhost:9257");
    IList<Snsr_Data_Val> result = null;
    redisManager.ExecAs<Snsr_Data_Val>(sensordata =>
    {
        result = sensordata.GetAll().Where(d => d.Category_ID == category_id).ToList();
    });
    redisManager = null;
    return result;
}

What worries me is that GetAll() may be time consuming. I remember in SQL Server we used something like .GetTable().Where(...), is there something of the sorts in Redis / NoSQL?

Community
  • 1
  • 1
progrAmmar
  • 2,606
  • 4
  • 29
  • 58
  • Take a loot at the linked Q&A where I've already answered a similar question. I was going to close it as *too broad*, but instead of this, I believe the other Q&A will give you some guidance of how to achieve your goals :) – Matías Fidemraizer Oct 17 '15 at 20:51
  • Hi Matias, Thanks for the redirect but as I told you I am new to Redis, but I guess the problem is I am thinking it as an RDBMS person. Can you give me an example using the StackServer.Redis if it's not much trouble, it will be a lot of help thanks. – progrAmmar Oct 18 '15 at 10:14
  • At the end of the day, what makes different using the `redis-cli` or implementing the same commands using a client? Instead of trying to thinks as a RDBMS person, leave away that toxic thinking that helps nothing when you want to implement a NoSQL solution. And Redis is even more different than other NoSQL solutions. Think everything as if you would building SQL indexes programatically from scratch. – Matías Fidemraizer Oct 18 '15 at 10:33
  • Thanks for the advice @MatíasFidemraizer. I have been looking into Hashes and I believe it may solve my problem if I choose StoreAsHash. But again, I know little of StackServer's redis, I will dig a bit deeper into it, But if you can guide me how to retrieve a list based on a property value how can I achieve that? – progrAmmar Oct 18 '15 at 11:16
  • You won't be able to get a list based on a property value. You need to build a set where you'll add the ids of objects that contain a property with the desired value. – Matías Fidemraizer Oct 18 '15 at 11:20
  • So that means where I am storing my data, I should I also create a SetEntry with Category_ID, So whenever I need a specific query I can just get it from the Set where I have stored it. Is that correct – progrAmmar Oct 18 '15 at 11:41
  • Now you're in the right track ;) – Matías Fidemraizer Oct 18 '15 at 11:43
  • I've another Q&A that can be useful for you to continue learning how to model data in Redis: http://stackoverflow.com/questions/19066462/something-like-a-tag-cache-and-querying-it-for-suggesting-them-using-redis (a Q&A where I answered myself :D) – Matías Fidemraizer Oct 18 '15 at 11:46
  • Thanks, it was really helpful. I believe the choice of Database type (string based, list based, document based etc) is also necessary for the type of project. I saw document based nosql databases and it works perfect. Just curious, in my previous approach with set based and string based entries, if I am saving an object twice (first with ID then within a set) doesn't my database grow exponentially? Like in the recent discussion you sent me you are saving the same object with different combination of tags – progrAmmar Oct 19 '15 at 01:06

0 Answers0