Redis Tree (Ploytree) Structure Module
Last updated Mar 28, 2026
84
Stars
3
Forks
0
Issues
0
Stars/day
Attention Score
9
Language breakdown
Rust 43.6%
Shell 16.3%
Python 15.1%
Dockerfile 14.9%
Makefile 10.1%
▸ Files
click to expand
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 functionQuick Start
Docker
# 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
Rust
- Run
cargo build - Start a redis server with the
redistreemodule
redis-server --loadmodule ./target/release/libretree.so
* Mac: redis-server --loadmodule ./target/release/libretree.dylib
- Open a Redis CLI, and run
tree.init hello "a (b (d) c)".
Commands
tree.init key tree_valuetree.get keytree.del keytree.getsubtree key nodevaluetree.delsubtree key nodevaluetree.setsubtree key nodevalue tree_valuetree.getancestors key nodevaluetree.getdescendants key nodevaluetree.getfather key nodevaluetree.getchildren key nodevalue
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
- Install Rust
- Install Redis, most likely using your favorite package manager (Homebrew on Mac, APT or YUM on Linux)
Makefile
build build retree docker image
builder build rust cross-compiler base image, for mac developers
clean clean
push push to pornhub
test do some behavioral tester
tester build tester image
TODO
- Postgres ltree gist index
- Postgres ltree query
- Hash Index
Thanks
🔗 More in this category