问题
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