使用redis进行树数据结构 [英] using redis for tree data structure

查看:123
本文介绍了使用redis进行树数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为基于树的键值开发一个缓存系统(非常类似于Windows注册表编辑器).

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

其中缓存键是表示树中该值的路径的字符串,它本身可以是原始类型(int,string,bool,double等)或子树.

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.

例如:

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

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

我曾考虑过将Redis用作简单的缓存实现,但是朴素的键值会忽略树的层次结构.

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

我正在寻找

key = root\x\y\z

尽管朴素的键值已经存在于缓存中,但找不到它.

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

我能想到的最好的数据结构是前缀树(Trie),它可以以更有效的方式处理键并可以轻松地找到我上面提到的子字符串的情况.

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.

我还没有发现Redis可以处理这种数据strcutre的实现.

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

Redis可以处理这种缓存吗?如果没有,还有替代方法可以使用吗?

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

推荐答案

尝试此redis 树模块.它在redis中提供了原生的polytree数据结构

Try this redis tree module. It provide native polytree data structure in redis

这篇关于使用redis进行树数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆