我试图在Redis上使用有理数实现嵌套集数据模型本文中描述了http://arxiv.org/abs/0806.3115
但是,经过两周的学习,我坚持设计......这里是我的架构
嵌套集模型
**Add Nodes**(name, is_root= nil, namespace=nil){
$id = INCR namespace:nodes:counter *//generate unique id for every node*
HSET namespace:nodes:by_id = field:$id value: {Json object with numerator and denominator of node and next sibling}
HSET namespace:nodes:by_name field:hash($node name) value:$id *// For search with node name*
*// the score is obtained with numerator/denominator, the set contains all item ids of a category*
Create an entry on ZSET namespace:nodes_list
if is_root{
*//for performance purpose instead of calculate the root nodes with filter on ZSET, store all here*
Insert id into SET named: namespace:root_nodes:ids
}}
**Get whole Node Tree** {
For each id stored on namespace:root_nodes:ids($id){
GET namespace:nodes:$Id values nv dv snv sdv
*//stuck here*
}
}
我的设计可以让整棵树速度适中吗?提示?
也许其他数据结构更好但不知道,你呢?
像亚马逊这样的类别包含多个类别中的项目,如果儿童猫上有项目,则父猫也包含项目。