首页 > 解决方案 > How to keep sql tables in redis efficiently

问题描述

I searched on net but couldnt find any brieny description for it, so here its;

There is Products table, here is the example of 2 rows;

ID Name Price Expire CreatedDate ...
1  A    12    4      01.01.2019 
2  B    25    5      01.01.2019

there is 100 million more which needed to be searched and retrieve fast.

What I learn with some search Redis keeps data as JSON,

so I create a key composite of tablename:row_primary_key and write this 100 million rows from database to redis with keys as(and value is entire row serialized json string)

Products:1
Products:2
...

So I am able to get any particular row with key, but I think you asked the question at the moment what if I need make search with other columns, for example Price or Name?

What first thing to come in mind generate another 100 million in Redis with keys composite of 'tablename:price' but it sounds extremely frustrating and waste of memory(I don't say even when there is 10 more columns suppose to be in search).

So whats the best and most efficient way to store rows from SQL table in Redis?

And I am using StackExchange.Redis library.

标签: redisstackexchange.redis

解决方案


推荐阅读