简体   繁体   English

Redis - 缓存数据的最佳方式

[英]Redis - best way to cache the data

I have 3 types of values. 我有3种类型的值。

Type1 - In millions
Type2 - In hundreds
Type3 - In tens

For each type1, all type2 should be processed by type3. 对于每个type1,所有type2都应由type3处理。

I can use set. 我可以用套装。

Type1#Type3 = {Type2 values}

Or 要么

Type1#Type2 = {Type3 values}

If I keep Type3 as a key, more memory occupied by the set. 如果我将Type3作为键,则该集占用更多内存。

Or is there any better way to store this type data? 或者有更好的方法来存储这种类型的数据吗?

I evaluated hash which occupies more memory than set. 我评估了占用比设置更多内存的哈希。 I evaluated with ziplist compression for hash. 我用ziplist压缩评估哈希值。

Any suggestions? 有什么建议么?

If you can tolerate splitting, here is another way: 如果你能容忍分裂,这是另一种方式:

First HashMap with key as a type1 value and value as a : separated list of type2 values linked to that type 1 value 第一个HashMap,其中键作为type1值,值作为:与该类型1值链接的type2值的分隔列表

type1_a => type2_b:type2_c..

type1_b => type2_k:type2_d..

Second HashMap with key as a type2 value and value as the corresponding type3 value 第二个HashMap,其中key作为type2值,value作为相应的type3值

type2_a => type3a

type3_b => type3b

for type2_key in firstHashMap.get(type1_key).split(':') secondHasMap.get(type2_key)

Also, you can look into Lua script to avoid doing the above on client side. 此外,您可以查看Lua脚本以避免在客户端执行上述操作。

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

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