DEV Community

Cover image for Intro to Redisgraph
Kisore Subburaman for DevParadise

Posted on

Intro to Redisgraph

Hey guys! This is a series about RedisGraph. For the people out there who are new to this term, it 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. Don't panic, it is not as difficult as it seems, in a nutshell, it is a graph-based database where we're going to handle data through nodes and relationships. For guys who have worked in Neo4j, this would be a piece of cake.You can visit the official site here Redisgraph

Let's see the primary features:

  1. It is based on the Property Graph Model.
  2. Nodes are treated as vertices and edges are treated as relationships, that may have attributes.
  3. Nodes can be labeled.
  4. Relationships have a relationship type.
  5. Graphs are represented as sparse adjacency matrices, Cypher as a query language
  6. Cypher queries are translated into linear algebra expressions

Setting up redisgraph

You can find the installation and setup process here Setup Redisgraph

Why should I use Redisgraph?

  • Faster : Redisgraph provides faster access and retrieval of data.

  • Straightforward : Since it is based on nodes and relations, it is not a hard nut to crack.

  • Understandable : Queries are simple commands and clear.

  • Visual view : To interact with data visually, Redislabs provides a service RedisInsight, we will dig deeper into that service later in our tutorial.

Supported Datatypes

  • Integer
  • NULL
  • String
  • Boolean
  • Double

Let's get our hands dirty

We take an example of creating employees of an organization and perform CRUD.

  • CREATE
    CREATE (e:emp{id:1, name: 'John', age: '24', designation: 'developer'}) RETURN e;

    CREATE (e:emp{id:2, name: 'Jessie', age: '27', designation: 'tester'}) RETURN e;

Here,
* e - alias of the emp, we can use it within this entire command anywhere we needed.
* emp - name of the node.
* data will be given as key-value pair (object).
* RETURN - return the data after creation.

  • MATCH

It matches all docs(documents) when no condition is given explicitly and when given, it retrieves only the docs matching the condition.

To return the list of all employees

 MATCH (e:emp) RETURN e;

To fetch on condition basis

MATCH (e:emp{id:1}) RETURN e;

OR

MATCH (e:emp) WHERE e.id = 1 RETURN e;

Both ways returns the doc of an employee having id 1.

  • SET

To update a single property

 MATCH (e:emp{id: 1}) SET e.age=28 RETURN e;

To update more than one property

MATCH (e:emp{id: 1}) SET e.age=28,e.designation=’senior developer’ RETURN e;
  • DELETE

To delete based on condition

MATCH (e:emp{id:2}) DELETE e;   

Boom! It deletes the employee with id 2.
To delete all the docs

MATCH (e:emp) DELETE e;

Top comments (0)