RedisGraph is a graph database built on Redis. It is a Redis module that extends the DBMS to provide graph database capabilities, including the property graph data model and graph query processing. RedisGraph exposes Cypher as its query language.
Graphs in RedisGraph are represented as sparse adjacency matrices. RedisGraph uses SuiteSparse, a package implemented GraphBLAS that provides a linear algebra interface for implementing graph algorithms, to represent sparse matrices and implement physical query operators, such as Conditional Traverse.
RedisGraph was created in 2018 by Roi Lipman from Redis Labs.
RedisGraph v.1.0 was released in November 2018. RedisGraph also released their benchmarking result on their system.
RedisGraph was also published as a short paper, RedisGraph GraphBLAS Enabled Graph Database (by Cailliau et al.), in IEEE IPDPS (GrAPL Workshop) in 2019.
RedisGraph v.2.0 was released in January 2020 with a full-text search, more Cypher language coverages, and performance improvement.
Graphs in RedisGraph are stored in sparse representations supported by GraphBLAS.
According to GraphBLAS, it supports Compressed Sparse Row (CSR), Compressed Sparse Column (CSC), and Coordinate List (COO) to compress matrices. The key idea of all the sparse representations is to suppress zero/undefined values in matrices by storing only indices of non-zero elements.
Otherwise, there is no specific compression scheme for properties and attributes in RedisGraph.
RedisGraph supports the property graph data model. Specifically, the data model defines nodes and edges. Nodes can have multiple labels, and edges can have a relationship type. Every node and edge can have multiple properties (i.e., attributes).
RedisGraph provides full-text indexes for querying nodes or edges by texts.
Specifically, RedisGraph uses RediSearch, which is an open-source Redis module. RediSearch uses Compact Prefix Tree (Radix Tree) and Trie (Prefix Tree) data structures.
RedisGraph provides a physical operator, Value Hash Join, which is used to join the records (i.e., tuples) from two child operators.
Although the name sounds like a hash join operator, the implementation is more similar to a sort-merge join. Their join operator starts with creating an array of the left operator's records. The array of the left operator's records will be sorted. The operator will iteratively probe the sorted array with the records from the right operator using a binary search algorithm.
RedisGraph uses the pull-based tuple-at-a-time query processing model to process queries.
When RedisGraph receives a query, RedisGraph will generate and then optimize a query plan according to the query. The query plan consists of physical query operators. All the query operators share the same interface, called Op.
The tuple-at-a-time query processing engine will then process the query plan by calling the Consume
function at the root of the query plan. The Consume
function for every query operator commonly calls its children's Consume
function recursively.
The implementations of graph-specific operators (such as Conditional Traverse) are mainly implemented with SuiteSparse, a linear algebra package for implementing graph algorithms conforming the GraphBLAS specification. The Conditional Traverse operator, which is used SuiteSparse, contains computing single-source breadth-first search (BFS) algorithm multiple times. The multiple-time single-source breadth-first search algorithm is implemented with a matrix-matrix multiplication in SuiteSparse.
The Conditional Traverse operator can form a matrix-matrix multiplication chain between adjacency matrices with different or the same relationship types if it needs to compute multiple-hop queries. Each matrix-matrix multiplication computes multiple-time single-source breadth-first search algorithms. Rather, the operator can use element-wise matrix multiplications to selectively choose only the frontier of the search that matches the node label depending on user queries.
Some operators allow a number of records to be batched before executing the operators' logic; for instance, the Conditional Traverse operator allows 16 (by default) records to be batched before calling a matrix-matrix multiplication.
Stored Procedures Cypher Command-line / Shell
RedisGraph exposes 9 commands:
GRAPH.CONFIG
stores/retrieves the current value of a RedisGraph configuration parameter.
GRAPH.CONSTRAINT
creates/drops graph constraints.
GRAPH.DELETE
deletes a graph specified.
GRAPH.LIST
lists all graphs managed by RedisGraph.
GRAPH.EXPLAIN
explains a query plan generated from a Cypher query.
GRAPH.PROFILE
profiles the time/records spent/produced by the query process of a Cypher query.
GRAPH.QUERY
executes a Cypher query.
GRAPH.RO_QUERY
executes a read-only Cypher query.
GRAPH.SLOWLOG
lists the 10 slowest queries of a specific graph.
The query must be specified in Cypher with limited coverage.
Users can use Redis client interfaces to interact with RedisGraph on Redis servers. Alternatively, users can use existing libraries to interact with RedisGraph. RedisGraph also exposes scripts for bulk inserting a graph.
RedisGraph stores a node or an edge by treating it as a document and putting it into Redis using RediSearch. The document is physically stored in Redis's managed hash tables. Different labels or relationship types create different indexes in RediSearch, which are Radix Tree (the rax implementation). Given a node has more than one label, the node is indexed across multiple indexes. The document treats properties in a node or an edge as fields.
RedisGraph allows users to provide their stored procedures written in C. Each stored procedure must be provided and registered before compiling the RedisGraph module. The registration must be currently done in this C file and must be exposed in this header file.
The valid stored procedure must contain a stored procedure name, a number of input arguments, an output specification (i.e., output data types, output field names), and three main routines. The three main routines include Invoke
, Step
, and Free
.
Invoke
will be called first after the stored procedure is called.
Step
will be called multiple times to produce a result tuple per Step
call.
Free
will be called to clean up allocated memory.
Users may store the state of each procedure call using the private_data
pointer shared across these routines.
RedisGraph uses shared-nothing architecture.
https://github.com/RedisGraph/RedisGraph
https://redis.io/docs/stack/graph/
Redis Ltd.
2018
C, C#, Elixir, Go, Java, JavaScript, Julia, PHP, Python, Ruby, Rust