简体   繁体   中英

How to do Redis tree and optimize it + Node.js

I need to have cached data that will be used by several node.js workers. Below, there is hierarchy of that data, it's 3 layer deep :

Redis数据结构

Each category has the same subcategories, and both of them are of fixed size. Each "Data" contains 4 fields, one of which is an unique ID. There will be quite a lot of "Data" inserting and deleting.

What is the best way to implement such database in Redis? Hash sets for cat+subcat since I have fixed amount of them, and hash set also for Data becouse of that unique ID every field has?

Thanks!

There are multiple ways you can achieve this. One is to store hashsets with names concatenating

"category:subcategory:data" -> key1: value1, key2: value2, ...

Through this you can fetch your information if you know what you are looking for. If searching is your issue then you'll need to add more calls to the redis server which will have a performance impact. But it all depends on how you want to search that data.

As meta information, you can create separate hashsets to facilitate not loosing an data.

List of categories
Hashset of categories -> SubCategories
categories:subcategories -> 4data points
categories:subcategories:data -> keys and values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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