DEV Community

Cover image for Intro to Redisgraph
Kisore Subburaman for DevParadise

Posted on

9 5 1 1 1

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;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

To fetch on condition basis

MATCH (e:emp{id:1}) RETURN e;
Enter fullscreen mode Exit fullscreen mode

OR

MATCH (e:emp) WHERE e.id = 1 RETURN e;
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

To update more than one property

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

To delete based on condition

MATCH (e:emp{id:2}) DELETE e;   
Enter fullscreen mode Exit fullscreen mode

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

MATCH (e:emp) DELETE e;
Enter fullscreen mode Exit fullscreen mode

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay