This is a straightforward and rather naïve implementation of a Blueprints-enabled graph over Redis.
Blueprints is a database-agnostic library for handling graphs. Blueredis allows you to run Blueprints on top of redis. Also see Pipes and Gremlin to see what this integration will also allow you to do.
Requires Redis 2.x compatible version of JRedis (git clone this repo, and you'll get a jar)
Graph db = new RedisGraph();
String password = "pass";
Graph db1 = new RedisGraph(password);
String host = "127.0.0.1";
int port = 6379;
Graph db2 = new RedisGraph(host, port);
int database = 10;
Graph db3 = new RedisGraph(host, port, pass, database);
After this you work with the database as with any Blueprints-enabled graph.
RedisGraph handles id creation for you. Any id parameter passed to addVertex/addEdge will be ignored. All ids are of type long
By default all properties are saved and retrieved as strings, regardless of the type of object you pass to
addVertex
. If you want to save actual objects/values, call graph.serializeProperties(true)
. Note though, that it
uses Base64 encoding on top of Java serialization so it may take up a lot of space.
Currently transactions are not supported
WARNING! Indexing support that's bundled with Blueredis is rather resource intensive, manipulates quite a few key-value pair in redis and negatively affects performance. If speed is your primary concern, don't use the default indexing implementation
Blueredis implements an index for both vertex and edge properties. This implementation is based on A fast, fuzzy, full-text index using Redis.
By default indexing is off. To turn it on, call graph.setIndexing(true)
. To turn it back on, call graph.setIndexing(false)
.
You may wish to implement your own indexing service. To do this:
- implement Blueprints'
Index
andAutomaticIndex
interfaces - override Blueredis'
RedisIndexManager
class - call
graph.setIndexing(true, yourManagerInstance)
and pass an instance of your indexManager to it
Each vertex is represented by the following keys:
vertex:ID
, vertex id. This one is used to test if a vertex existsvertex:ID:properties
, a hash of all vertex propertiesvertex:ID:edges:in
, a set of all incoming edgesvertex:ID:edges:out
, a set of all outgoing edges
Each edge is represented by the following keys:
edge:ID
, edge id. This one is used to test if an edge existsedge:ID:label
, a string containing the edge's labeledge:ID:in
, index of "in" vertexedge:ID:out
, index of "out" vertexedge:ID:properties
, a hash of all edge properties
This are just some keys that hold values necessary for Blueredis to work:
globals:next_vertex_id
, a counter that's incremented each time a new vertex is addedglobals:next_edge_id
, a counter that's incremented each time a new edge is addedglobals:vertices
, a sorted list of all vertex idsglobals:edges
, a sorted list of all edge ids
This section describes default indexing support that's bundled with Blueredis. You're free to implement your own.
Indices are stored in keys that all start with an index:...
index:auto
- prefix for all automatic indicesindex:manual
- prefix for all manual indices For all of the above:index:type:index_name
, whereindex_name
is a user-supplied index name - prefix for index data forindex_name
index:type:index_name:key_name
, wherekey_name
is a user-supplied key name - prefix for index data forkey_name
keyindex:type:index_name:key_name:metaphone
, wheremetaphone
is a calculated metaphone for a value - contains a list of vertex ids that have a key key_name with a value whose metaphone matches metaphone
index:meta:indices:auto
- a list of automatic indicesindex:meta:indices:manual
- a list of manual indicesindex:meta:auto
- prefix for all meta information on automatic indicesindex:meta:manual
- prefix for all meta information on manual indices For index:meta:(auto|manual) above:index:meta:type:index_name:class
, whereindex_name
is a user-supplied index name - contains what class the index works on: vertex, edge, etc.index:meta:type:index_name:keys
, whereindex_name
is a user-supplied index name - contains a list of keys for this index
RedisGraph now passes tinkerpop's tests.
An old benchmark can be found here: benchmarks page in wiki. Note that reeds seems to perform better under load than during singular requests. A newer benchmark will be published as soon as there's one :)