MCPcopy Index your code
hub / github.com/OhBonsai/RedisTree

github.com/OhBonsai/RedisTree @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
355 symbols 1,006 edges 21 files 125 documented · 35%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RedisTree

RedisTree is a Redis module that implements Polytree as a native data type. It allows creating,locating,pushing and detaching tree from Redis keys. RedisTree has been running in production environment for one year

  • 哥,来一趟不容易,点个Star呗
  • Could you give me a star...
  • Donne moi une étoile
  • 星をください
  • 나에게 별을 줘

Why?

Store organization data in redis, Need ploytree and some helper function

Quick Start

# run redis by docker
docker run -p 6379:6379 -d --name redis-redistree ohbonsai/redistree

# exec redis-cli in redis container
docker exec -it redis-redistree /bin/sh
redis-cli

Commands

  • tree.init key tree_value
  • tree.get key
  • tree.del key
  • tree.get_subtree key node_value
  • tree.del_subtree key node_value
  • tree.set_subtree key node_value tree_value
  • tree.get_ancestors key node_value
  • tree.get_descendants key node_value
  • tree.get_father key node_value
  • tree.get_children key node_value

Init Get Del tree from String

    a
  /    \
 b      c
 |
 e

127.0.0.1:6379> tree.init hello "a (b (d) c)"
OK
127.0.0.1:6379> tree.get hello
"a( b( d ) c )"
127.0.0.1:6379> tree.del hello
OK
127.0.0.1:6379> tree.get hello
(nil)
127.0.0.1:6379> tree.init hello "a (("
(error) ERR () is not closed or no root

Fetch Detach

USA government tree

         |----------------------------------USA----------------------------------|
         |                                  |                                    |
    Legislature                      ExecutiveJudiciary                      Judiciary
   /         \                              |                                    |
House      Senate                      WhiteHouse                          SupremeCourt
 |            |                             |                                    |          
Pelosi      Harris                        Biden                               Roberts


127.0.0.1:6379> tree.init usa "USA (Legislature (House (Pelosi) Senate (Harris))ExecutiveJudiciary (WhiteHouse (Biden))Judiciary (SupremeCourt (Roberts)))"
OK

# Get subtree of executive judiciary
127.0.0.1:6379> tree.get_subtree usa ExecutiveJudiciary
"ExecutiveJudiciary( WhiteHouse( Biden ) )"

# Add secretary for Biden
127.0.0.1:6379> tree.set_subtree usa Biden "Blinken"
OK
# now biden has secretary
127.0.0.1:6379> tree.get_subtree usa Biden
"Biden( Blinken )"

# Detach Blinken from Biden
127.0.0.1:6379> tree.del_subtree usa Blinken
"Blinken"
127.0.0.1:6379> tree.get_subtree usa Biden
"Biden"


# Get Harris ancestors 
127.0.0.1:6379> tree.get_ancestors usa Harris
1) "Senate"
2) "Legislature"
3) "USA"

# Get Harris Father node
127.0.0.1:6379> tree.get_father usa Harris
"Senate"

# Get Legislature Children 
127.0.0.1:6379> tree.get_children usa Legislature
1) "House"
2) "Senate"


# Get Legislature Descendants(BFS)
127.0.0.1:6379>  tree.get_descendants usa  Legislature
1) "Legislature"
2) "House"
3) "Senate"
4) "Pelosi"
5) "Harris"


Run

Linux

redis-server --loadmodule yourpath/libretree.so

Mac

redis-server --loadmodule ./target/debug/libretree.dylib

Config

loadmodule /yourpath/libretree.so

Dev

Prerequisites

  • Rust: Module written in rust
  • Docker: For Cross Compile and Block box Test

Makefile

build                          build retree docker image
builder                        build rust cross-compiler base image, for mac developers
clean                          clean
push                           push to docker hub
test                           do some behavioral tester
tester                         build tester image

TODO

  • Postgres ltree gist index
  • Postgres ltree query
  • Hash Index

Thanks

Extension points exported contracts — how you extend this code

Split (Interface)
Split tree node into data item and children iter. [3 implementers]
deps/trees/src/bfs.rs
TupleTree (Interface)
For tuple notations to construct `Tree`. [1 implementers]
deps/trees/src/tuple.rs
TupleForest (Interface)
For tuple notations to construct `Forest`.
deps/trees/src/tuple.rs
RefCount (Interface)
(no doc) [1 implementers]
deps/trees/src/rc.rs

Core symbols most depended-on inside this repo

forward
called by 45
deps/trees/src/walk.rs
as_mut
called by 42
deps/trees/src/node.rs
as_ref
called by 39
deps/trees/src/node.rs
map
called by 32
deps/trees/src/bfs.rs
root_mut_
called by 27
deps/trees/src/tree.rs
root
called by 21
deps/trees/src/tree.rs
into_iter
called by 19
deps/trees/src/into_iter.rs
root_mut
called by 18
deps/trees/src/tree.rs

Shape

Method 201
Function 115
Class 27
Enum 8
Interface 4

Languages

Rust97%
Python3%

Modules by API surface

deps/trees/src/rc.rs65 symbols
deps/trees/src/node.rs53 symbols
deps/trees/src/forest.rs40 symbols
deps/trees/src/walk.rs32 symbols
deps/trees/src/tree.rs31 symbols
deps/trees/src/bfs_impls.rs20 symbols
deps/trees/src/lib.rs18 symbols
src/lib.rs17 symbols
deps/trees/src/bfs.rs15 symbols
deps/trees/src/tuple.rs13 symbols
deps/trees/src/node_vec.rs13 symbols
tests/test_commands.py9 symbols

For agents

$ claude mcp add RedisTree \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact