using redis for tree data structure

冷暖自知 提交于 2019-12-11 18:29:59

问题


I need to develop a cache system for tree based key-value (very similar to windows registry editor).

in that cache keys are strings which represents path in the tree to the value,which can be primitive type(int,string,bool,double etc.) or subtree by it self.

for example :

key = root\x\y\z\w , value = the whole subtree under w

key = root\x\y\z\w\t , value = integer 

I thought about using Redis as simple cache implemntation, but naive key-value will miss the point of tree hierarchy.

in addition, in this naive way , guessing I have in cache already

key = root\x\y, value = the whole subtree under y

and i am looking for

key = root\x\y\z

the naive key-value won't find it although it is already exist in cache.

the best data strucutre which I can think about is a prefix-tree (Trie) which can handle the keys in more efficient way and can easily find cases of sub-string as I mentioned above.

I could not find any implmentation of Redis which can handle this data strcutre yet.

Can Redis handle this kind of cache? if not,there is an alternative strcuture to use?


回答1:


Redis doesn't do trees (yet). If you must have a tree-like structure stored in Redis, I recommend you look at http://rejson.io.

Alternatively, you can develop a Redis module that does anything you want/need.

Disclaimer: I am one of ReJSON's authors.

xref: https://groups.google.com/d/msg/redis-db/ROSocq9sQ34/NmxeF0QFAQAJ



来源:https://stackoverflow.com/questions/49974869/using-redis-for-tree-data-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!