As of July 5th, 2023 RedisGraph is no longer under active development. We do not plan to release new features (2.12 is the last feature-bearing release), but we will continue to release patches until January 31, 2025.
You can read more about the end of life of RedisGraph here.
RedisGraph is the first queryable Property Graph database to use sparse matrices to represent the adjacency matrix in graphs and linear algebra to query the graph.
Primary features:
- Adopting the Property Graph Model
- Nodes (vertices) and Relationships (edges) that may have attributes
- Nodes can have multiple labels
- Relationships have a relationship type
- Graphs represented as sparse adjacency matrices
- OpenCypher with proprietary extensions as a query language
- Queries are translated into linear algebra expressions
To see RedisGraph in action, visit Demos. To read the docs, visit redis.io.
Once loaded you can interact with RedisGraph using redis-cli.
Here we'll quickly create a small graph representing a subset of motorcycle riders and teams taking part in the MotoGP league, once created we'll start querying our data.
The format of results through redis-cli
is described in the RedisGraph documentation.
$ redis-cli
127.0.0.1:6379> GRAPH.QUERY MotoGP "CREATE (:Rider {name:'Valentino Rossi'})-[:rides]->(:Team {name:'Yamaha'}), (:Rider {name:'Dani Pedrosa'})-[:rides]->(:Team {name:'Honda'}), (:Rider {name:'Andrea Dovizioso'})-[:rides]->(:Team {name:'Ducati'})"
1) 1) Labels added: 2
2) Nodes created: 6
3) Properties set: 6
4) Relationships created: 3
5) "Query internal execution time: 0.399000 milliseconds"
Now that our MotoGP graph is created, we can start asking questions, for example: Who's riding for team Yamaha?
127.0.0.1:6379> GRAPH.QUERY MotoGP "MATCH (r:Rider)-[:rides]->(t:Team) WHERE t.name = 'Yamaha' RETURN r.name, t.name"
1) 1) "r.name"
2) "t.name"
2) 1) 1) "Valentino Rossi"
2) "Yamaha"
3) 1) "Query internal execution time: 0.625399 milliseconds"
How many riders represent team Ducati?
127.0.0.1:6379> GRAPH.QUERY MotoGP "MATCH (r:Rider)-[:rides]->(t:Team {name:'Ducati'}) RETURN count(r)"
1) 1) "count(r)"
2) 1) 1) (integer) 1
3) 1) "Query internal execution time: 0.624435 milliseconds"
Requirements:
-
The RedisGraph repository:
git clone --recurse-submodules -j8 https://github.com/RedisGraph/RedisGraph.git
-
On Ubuntu Linux, run:
apt-get install build-essential cmake m4 automake peg libtool autoconf python3
-
On OS X, verify that
homebrew
is installed and run:brew install cmake m4 automake peg libtool autoconf
.- The version of Clang that ships with the OS X toolchain does not support OpenMP, which is a requirement for RedisGraph. One way to resolve this is to run
brew install gcc g++
and follow the on-screen instructions to update the symbolic links. Note that this is a system-wide change - setting the environment variables forCC
andCXX
will work if that is not an option.
- The version of Clang that ships with the OS X toolchain does not support OpenMP, which is a requirement for RedisGraph. One way to resolve this is to run
To build, run make
in the project's directory.
Congratulations! You can find the compiled binary at src/redisgraph.so
.
First, install required Python packages by running pip install -r requirements.txt
from the tests
directory.
If you've got redis-server
in PATH, just invoke make test
.
Otherwise, invoke REDIS_SERVER=<redis-server-location> make test
.
For more verbose output, run make test V=1
.
The RedisGraph build system runs within docker. For detailed instructions on building, please see here.
RedisGraph is hosted by Redis, so you'll first have to load it as a Module to a Redis server. Redis 6.2 is required for RedisGraph 2.12.
We recommend having Redis load RedisGraph during startup by adding the following to your redis.conf file:
loadmodule /path/to/module/src/redisgraph.so
In the line above, replace /path/to/module/src/redisgraph.so
with the actual path to RedisGraph's library.
If Redis is running as a service, you must ensure that the redis
user (default) has the necessary file/folder permissions
to access redisgraph.so
.
Alternatively, you can have Redis load RedisGraph using the following command line argument syntax:
~/$ redis-server --loadmodule /path/to/module/src/redisgraph.so
Lastly, you can also use the MODULE LOAD
command. Note, however, that MODULE LOAD
is a dangerous command and may be blocked/deprecated in the future due to security considerations.
Once you've successfully loaded RedisGraph your Redis log should have lines similar to:
...
30707:M 20 Jun 02:08:12.314 * Module 'graph' loaded from <redacted>/src/redisgraph.so
...
If the server fails to launch with output similar to:
# Module /usr/lib/redis/modules/redisgraph.so failed to load: libgomp.so.1: cannot open shared object file: No such file or directory
# Can't load module from /usr/lib/redis/modules/redisgraph.so: server aborting
The system is missing the run-time dependency OpenMP. This can be installed on Ubuntu with apt-get install libgomp1
, on RHEL/CentOS with yum install libgomp
, and on OSX with brew install libomp
.
You can call RedisGraph's commands from any Redis client.
$ redis-cli
127.0.0.1:6379> GRAPH.QUERY social "CREATE (:person {name: 'roi', age: 33, gender: 'male', status: 'married'})"
You can interact with RedisGraph using your client's ability to send raw Redis commands.
Depending on your client of choice, the exact method for doing that may vary.
This code snippet shows how to use RedisGraph with raw Redis commands from Python via redis-py:
import redis
r = redis.StrictRedis()
reply = r.execute_command('GRAPH.QUERY', 'social', "CREATE (:person {name:'roi', age:33, gender:'male', status:'married'})")
Some languages have client libraries that provide support for RedisGraph's commands:
Project | Language | License | Author | Stars | Package | Comment |
---|---|---|---|---|---|---|
jedis | Java | MIT | Redis | Maven | ||
redis-py | Python | MIT | Redis | pypi | ||
node-redis | Node.JS | MIT | Redis | npm | ||
nredisstack | .NET | MIT | Redis | nuget | ||
redisgraph-rb | Ruby | BSD | Redis | GitHub | ||
redisgraph-go | Go | BSD | Redis | GitHub | ||
rueidis | Go | Apache 2.0 | Rueian | GitHub | ||
ioredisgraph | JavaScript | ISC | Jonah | GitHub | ||
@hydre/rgraph | JavaScript | MIT | Sceat | GitHub | ||
php-redis-graph | PHP | MIT | KJDev | GitHub | ||
redisgraph_php | PHP | MIT | jpbourbon | GitHub | ||
redisgraph-ex | Elixir | MIT | crflynn | GitHub | ||
redisgraph-rs | Rust | MIT | malte-v | GitHub | ||
redis_graph | Rust | BSD | tompro | GitHub | ||
rustis | Rust | MIT | Dahomey Technologies | Crate | Documentation | |
NRedisGraph | C# | BSD | tombatron | GitHub | ||
RedisGraph.jl | Julia | MIT | xyxel | GitHub |
Read the docs at redisgraph.io.
Got questions? Feel free to ask at the RedisGraph forum.
Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or the Server Side Public License v1 (SSPLv1). See LICENSE.