2013-01-08 35 views
3

我正在尋找一種有效的方法來實施redis中的分層文件/文件夾樹,並且能夠輕鬆移動節點。如何在redis中實現文件夾分層樹?

/ 
    a/ 
    a1 
    a2 
    b/ 
     b1 
     b2 
     c/ 
      c1 
    x/ 
    x1 
    y/ 
     y1 

我想存儲上述樹,能夠輕鬆地使操作如

move node /a/b/c to /foo/a/b/c 
move node /a/b/c to /x/c 
delete node /a/b 

指針,以現有的實施模式等將是有益的。

回答

6

我設計的架構,這有助於一個很容易地添加,移動和重命名節點和條目

# **enode** a hierarchical directory in redis 
# A folder/node structure where nodes can have sub-nodes and entries. 
# Entries can have tags. 
# 
# Each entry gets an enodeid and an entryid 
# enodeid - The id of the directory that contains the entry 
# entryid - The id of this entry within this enode/directory 
# 
# The data schema is as follows 
# enodeid:kids - Sorted set containing the kids for each directory 
#     The topmost node is a string "root" and not a number 
#     The sort score is actually the enodeid of the corresponding kid 
#     so if /a has an enodeid of 2 and is a kid of root the entry is 
#     root:kids [2, "a"] 
#     If a directory /a/b exists and has an enodeid of 4 than 
#     2:kids = [4, "b"] - here 2 is the enodeid of '/a' 
# 
# enodeid:meta - Hash entry containing the name and parent of an enodeid 
#     2:meta = {name: "a", parentid: "root"} 
#     4:meta = {name: "b", parentid: 2} 
# 
# enode.next.id - Unique enode id's 
# 
# entry.next.id - Unique entry id's 
# 
# enodeid:entries - Sorted set containing the entries in a directory 
#      The sort score is the sequence number of the entry withi the directory 
#      moveEntry moves the entry up/down within this 
# 
# enodeid.entry.num - Unique entry id's for a given enodeid 
# 
# enodeid:tags - Sorted list of tags 
#     Score is tagcount, memeber is tag 
# 
# enodeid:axs - List of usernames that have access to this folder 
相關問題