Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Nowadays, graph-based data is everywhere. Facebook, Twitter, Google, and Pinterest are just a few companies that have realized the value of relationship data and are making the most of it.
RedisGraph is an open-source graph database built on Redis that adds new graph features via a native C implementation with a focus on performance.
Primary featuresof RedisGraph
Indexing and querying are simple and quick.
Memory-efficient custom data structures are used to store data in RAM.
On-disk persistence
OpenCypher, a popular graph query language, is used.
Sparse adjacency matrices are used to represent graphs.
Let's look at some of the major RedisGraph ideas using the Redis-CLI tool:
Graph construction
Entities are commonly described as nodes in a graph. In this example, we'll make a tiny graph containing both actors and movies and an "act" relation that connects actors to the films in which they appeared. The graph will be used. To run a CREATE query, use the QUERY command. This will add new entities and relations to our graph.
A subset of the openCypher graph language is accessible via RedisGraph. While only a few languages are available, there is enough functionality to extract useful information from your graphs. We'll use the GRAPH.QUERY command to run a query:
GRAPH.QUERY <graph_id> <query>
Let's run a few queries against our movie database.
Find the total, maximum, minimum, and average age of the cast of "Straight Outta Compton":
Our result-set header is the first row, and it labels each column according to the return clause.
Our query result is in the second row.
The Theory: Ideas behind RedisGraph
Representation
RedisGraph represents graphs with sparse adjacency matrices. Setting M's S, T entry to 1 (M[S, T]=1) records a directed relationship connecting source node S to destination node T in an adjacency matrix M. Source nodes are represented by matrix rows, whereas matrix columns represent destination nodes.
At least one matrix, named THE adjacency matrix, exists for every graph saved in RedisGraph (relation-type agnostic). Furthermore, each type-related relation has its specialized matrix. Consider the following graph with two sorts of relationships:
visits
friend
Three matrices make up the underlying graph data structure:
THE adjacency matrix identifies every connection in the graph. THE visit matrix identifies visit connections.
Marking friend relationships with a friend matrix
E is a 'visit' connection linking node A to node B.
THE adjacency matrix at position [A, B] is set to 1 by a 'visit' connection E that connects node A to node B. V[A, B] is also set to 1 by the visit matrix V.
One additional matrix is assigned per label to accommodate typed nodes, and a label matrix is symmetric with ones along the main diagonal. If node N is identified as a Person, the Person matrix P will set position P[N, N] to 1.
This approach allows RedisGraph to quickly modify its graph, including:
Matrixes are simply extended by adding more rows and columns when new nodes are added.
Setting the required entries at the relevant matrices to add new relationships
Clearing relevant entries by removing relationships
Nodes are deleted by simply deleting the matrix row/column.
Graph traversal is one of the key reasons we chose to describe our graphs as sparse matrices.
Traversal
Matrix multiplication is used to traverse a graph. For example, if we wanted to locate friends of friends for every node in the graph, we could use the formula FOF = F^2. The outcome matrix FOF summarises the traversal, and F stands for the friendship relation matrix. The FOF's columns indicate buddies who are two hops distant, whereas the rows represent source nodes: j is a friend of a friend if FOF[i,j] = 1.
Algebraic expression
We convert a search pattern like (N0)-[A]->(N1)-[B]->(N2)-[A]-(N3) into a series of matrix multiplications when we use it in a query. One alternative expression for the preceding example is A * B * Transpose (A).
Multiplication of matrices is an associative and distributive action. This offers us the option of deciding which terms to multiply first (preferring terms that will produce highly sparse intermediate matrices). It also allows for parallel computation when evaluating an expression, so we may compute AZ and BY simultaneously.
GraphBLAS
RedisGraph employs GraphBLAS, a standard API similar to BLAS, to perform these operations for sparse matrices. The current implementation uses the CSC sparse matrix format (compressed sparse columns).
Frequently Asked Questions
What is RedisGraph?
RedisGraph is a graph database built entirely on top of Redis, with new commands and capabilities added using the new Redis Modules API. Its primary characteristics are: Indexing and querying are simple and quick. Memory-efficient custom data structures are used to store data in RAM.
Is RedisGraph open source?
While Redis is open source, higher-value modules are now covered by a commercial agreement that restricts the sale of Redis-based products. Redis Labs has moved its database modules away from open source and toward a new commercial licensing system that includes source code access.
What is the difference between Redis replication and sharding?
Sharding, also known as partitioning, is the process of partitioning data by key; Replication, also known as mirroring, is copying all data. Sharding improves performance by lowering a single resource's hit and memory load. Replication is helpful in increasing readability.
Conclusion
In this article, we learned about Redis Graph.
Although RedisGraphit is still a young project, RedisGraph can be a feasible alternative to other graph databases. You can use its subset of operations to analyze and examine graph data. As a Redis Module, this project can be accessed by any Redis client without any modifications. With the help of the open-source, the Redis community plan to continue enhancing and expanding RedisGraph.
You can use Coding Ninjas Studioto practice various DSA questions asked in the interviews. It will help you in mastering effective coding techniques, and you will also get interview experienceswith people working in big companies.