Commands
Commands Overview
RedisGraph is a graph database built on Redis. This graph database uses GraphBlas under the hood for its sparse adjacency matrix graph representation.
To see RedisGraph in action, explore our demos.
To quickly try out RedisGraph, launch an instance using docker:
docker run -p 6379:6379 -it --rm redislabs/redisgraph
After you load RedisGraph, you can interact with it using redis-cli
.
Here we'll quickly create a small graph representing a subset of motorcycle riders and teams taking part in the MotoGP championship. Once created, we'll start querying our data.
redis-cli
$ 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) "Cached execution: 0"
6) "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) "Cached execution: 0"
2) "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) "Cached execution: 0"
2) "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
On OS X, verify that homebrew
is installed and run: brew install cmake m4 automake peg libtool autoconf
.
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 for CC
and CXX
will work if that is not an option.To build, run make
in the project's directory.
Congratulations! You can find the compiled binary at: src/redisgraph.so
RedisGraph is part of Redis Stack. See the Redis Stack download page for installaton options.
Before using RedisGraph, you should familiarize yourself with its commands and syntax as detailed in the command reference.
You can call RedisGraph's commands from any Redis client.
redis-cli
$ 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. The exact method for doing that depends on your client of choice.
This code snippet shows how to use RedisGraph with raw Redis commands from Python using redis-py:
import redis
r = redis.Redis()
reply = r.graph("social").query("MATCH (r:Rider)-[:rides]->(t:Team {name:'Ducati'}) RETURN count(r)")
Language-specific clients have been written by the community and the RedisGraph team for 6 languages.
The full list and links can be found on the Clients page.
The RedisGraph team maintains the redisgraph-bulk-loader for importing new graphs from CSV files.
The data format used by this tool is described in the GRAPH.BULK implementation details.
Got questions? Feel free to ask at the RedisGraph forum.
Redis Source Available License Agreement - see LICENSE
Commands Overview
The full functionality of RedisGraph is available through redis-cli
and the Redis API. RedisInsight is a visual tool that provides capabilities to design, develop and optimize into a single easy-to-use environment, and has built-in support for RedisGraph. In addition there are severeal client libraries to improve abstractions and allow for a more natural experience in a project's native language. Additionally, these clients take advantage of some RedisGraph features that may reduce network throughput in some circumstances.
RedisGraph supports a few run-time configuration options that can be defined when loading the module. In the future more options will be added.
RedisGraph supports a number of distinct data types, some of which can be persisted as property values and some of which are ephemeral.
RedisGraph implements a subset of the Cypher language, which is growing as development continues. This document is based on the Cypher Query Language Reference (version 9), available at OpenCypher Resources.
Quick start