Redis Tree(Ploytree) Structure Module

Overview

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

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 redistree module
    • Linux: 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_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

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

You might also like...
TreeFlat - the simplest way to build & traverse a pre-order Tree in Rust

TreeFlat is the simplest way to build & traverse a pre-order Tree for Rust. Alpha-relase! If you build a Tree in pre-order, and display in pre-order,

Bw-Tree for Rust
Bw-Tree for Rust

Bw-Tree for Rust This is a work-in-progress implementation of Bw-Trees for Rust. Nothing works, this is mostly for my own education right now. Design

A Redis module that provides rate limiting in Redis as a single command.

redis-cell A Redis module that provides rate limiting in Redis as a single command. Implements the fairly sophisticated generic cell rate algorithm (G

Automatically build a Rust module tree from the project directory structure

Hypermod An even lazier version of automod and supermod. Searches the src/ directory recursively for .rs files, then builds a module tree using the di

[POC] Redis Module for TiKV

RedisTikvPoc [POC] Redis Module for TiKV This is a POC repository. This Redis Module will add branch new Redis commands to operate TiKV data. After bu

A redis module that provides a type for inventory deduction in flash sales

A redis module that provides a type for inventory deduction in flash sales

A port of `java.util.*SummaryStatistics` as a Redis Module

RedisNumbersStats RedisNumbersStats is a Redis module that implements a Redis version of the Java Util *SummaryStatistics classes, such as DoubleSumma

A tree structure in Rust optimized for looking up domain names, with wildcard support

domain-lookup-tree Overview DomainLookupTree is a data structure which provides efficient domain name lookup matching with support for wildcard entrie

A prefix tree (trie) is a data structure that allows you to store an associative array whose keys are strings

RadixTrie A prefix tree (trie) is a data structure that allows you to store an associative array whose keys are strings. It is a root tree, each edge

Prefix tree (ordered map and set) data structure using 100% safe Rust

PFX: A 100% safe, blob-oriented prefix tree This crate provides a prefix tree map and set data structure, implemented purely in safe Rust. The API is

Basic template for an out-of-tree Linux kernel module written in Rust.

Rust out-of-tree module This is a basic template for an out-of-tree Linux kernel module written in Rust. Please note that: The Rust support is experim

Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. A tokei/scc/cloc alternative.

tcount (pronounced "tee-count") Count your code by tokens, types of syntax tree nodes, and patterns in the syntax tree. Quick Start Simply run tcount

Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

As-tree - Print a list of paths as a tree of paths 🌳

as-tree Print a list of paths as a tree of paths. For example, given: dir1/foo.txt dir1/bar.txt dir2/qux.txt it will print: . ├── dir1 │ ├── foo.tx

Nearest neighbor search algorithms including a ball tree and a vantage point tree.

petal-neighbors Nearest neighbor search algorithms including a ball tree and a vantage point tree. Examples The following example shows how to find tw

Untree converts tree diagrams produced by tree back into directory file structures.
Untree converts tree diagrams produced by tree back into directory file structures.

Untree: Undoing tree for fun and profit Untree converts tree diagrams produced by tree back into directory file structures. Let's say you have the fol

A sparse merkle tree lib focused on efficient on-chain proofs. Enforces ordering within the merkle tree.

sparse-merkle-tree The merkle tree functions are located in sparse.ak. Currently the supported functionality is: Verifying a new root with an added me

Redis re-implemented in Rust.

rsedis Redis re-implemented in Rust. Why? To learn Rust. Use Cases rsedis does not rely on UNIX-specific features. Windows users can run it as a repla

Redis library for rust

redis-rs Redis-rs is a high level redis library for Rust. It provides convenient access to all Redis functionality through a very flexible but low-lev

Owner
Bonsai
欲得决疑,要先究元
Bonsai
A tree structure in Rust optimized for looking up domain names, with wildcard support

domain-lookup-tree Overview DomainLookupTree is a data structure which provides efficient domain name lookup matching with support for wildcard entrie

null 18 Nov 28, 2022
A prefix tree (trie) is a data structure that allows you to store an associative array whose keys are strings

RadixTrie A prefix tree (trie) is a data structure that allows you to store an associative array whose keys are strings. It is a root tree, each edge

null 2 Jan 28, 2022
Untree converts tree diagrams produced by tree back into directory file structures.

Untree: Undoing tree for fun and profit Untree converts tree diagrams produced by tree back into directory file structures. Let's say you have the fol

Alecto Irene Perez 91 Jan 1, 2023
SegVec data structure for rust. Similar to Vec, but allocates memory in chunks of increasing size.

segvec This crate provides the SegVec data structure. It is similar to Vec, but allocates memory in chunks of increasing size, referred to as "segment

Jacob Ryan McCollum 30 Dec 16, 2022
Hypergraph is a data structure library to generate directed hypergraphs.

Hypergraph is data structure library to create a directed hypergraph in which a hyperedge can join any number of vertices.

Davy Duperron 112 Aug 24, 2021
Rust implementation of Adobe's stlab::forest data structure

skog Swedish for "forest". A pure rust implementation of Adobe's stlab::forest data structure. Introduction A "forest" is a tree-like data structure.

Julian 1 Dec 8, 2021
Ternary search tree collection in rust

tst Ternary search tree collection in rust with similar API to std::collections as it possible. Ternary search tree is a type of trie (sometimes calle

Alexey Pervushin 20 Dec 7, 2022
K-dimensional tree in Rust for fast geospatial indexing and lookup

kdtree K-dimensional tree in Rust for fast geospatial indexing and nearest neighbors lookup Crate Documentation Usage Benchmark License Usage Add kdtr

Rui Hu 152 Jan 2, 2023
B-Tree map for pub/sub services

submap B-tree map for pub/sub services. Create a new subscription map let mut smap: SubMap<Client> = SubMap::new(); where "Client" is a pub/sub client

Altertech 6 Sep 21, 2022
Recursive & Iterative Binary Search Tree Implementations within Rust

bst-rs Recursive & Iterative Binary Search Tree Implementations within Rust Table of Contents Personal Goals About Quick Start License Contributing In

Hamothy 6 Oct 1, 2022