Table of contents
1.
Introduction
2.
Graph types
2.1.
Nodes
2.2.
Relationships
2.3.
Paths
3.
Scalar types
3.1.
Strings
3.2.
Booleans
3.3.
Integers
3.4.
Floating-point values
3.5.
Geospatial Points
3.6.
Nulls
4.
Collection types
4.1.
Arrays
4.2.
Maps
5.
Frequently Asked Questions
5.1.
What can you do using Redis?
5.2.
Is Redis a database or a cache?
5.3.
What language is Redis written in?
5.4.
What is the usage of Redis?
5.5.
What are the ways to interact with Redis?
6.
Conclusion
Last Updated: Mar 27, 2024

Data types in Redis Graph

Author Manan Singhal
0 upvote

Introduction

RedisGraph supports a variety of data kinds, some of which can be saved as property values and others that are only temporary.

Graph types

Graph types are either structural pieces or projections of the graph. There is no way to save none as a property value.

Nodes

Nodes are persistent graph elements linked to one another through relationships.

They can represent through as many labels as they choose to describe their overall type. For instance, a node representing London may be constructed using the Place and City labels and retrieved using either or both in queries.

Nodes have properties that describe all of their important features. Our London node, for example, would have the following property set: name: 'London,' capital: True, elevation: 11.

Multiple labels can be supplied while querying nodes. Only nodes with all of the labels supplied will be matched:

$ redis-cli GRAPH.QUERY G "MATCH (n:Place:Continent) RETURN n"

Relationships

Relationships are graph elements that connect nodes in a lasting way.

They must all be of the same kind to represent the same thing. A RESIDENT OF connection, for example, can be used to link a Person node to a City node.

Connections between source and destination nodes are always directed.

Relationships, like nodes, have a set of properties that specify all of their important aspects.

Multiple types can be supplied when querying relationships when separated by kinds. Relationships that contain any of the kinds provided will be matched:

$ redis-cli GRAPH.QUERY G "MATCH (:Person)-[r:RESIDENT_OF|:VISITOR_TO]->(:Place {name: 'London'}) RETURN r"

Paths

Paths are alternating node and edge sequences that begin and conclude with a node.

They are not structural aspects of the graph, but queries can construct and return them.

The following query, for example, retrieves all pathways of any length linking the nodes London and New York:

$ redis-cli GRAPH.QUERY G "MATCH p=(:City {name: 'London'})-[*]->(:City {name: 'New York'}) RETURN p"

Scalar types

Queries can return any scalar type, which can be saved as property values on node and relationship objects.

Strings

Unicode character sequences are used in RedisGraph strings. When using Redis with a terminal emulator (such as invoking RedisGraph commands from the terminal via redis-cli)

Booleans

Boolean values have two options true or false. They are internally recorded as numerics, with 1 denoting true and 0 denoting false. Because RedisGraph compares types, 1 is not considered the same as true.

Integers

RedisGraph integers are all regarded as signed 64-bit integers.

Floating-point values

All floating-point values in RedisGraph are regarded as 64-bit signed doubles.

Geospatial Points

The Point data type is a pair of 32-bit floats that stores latitude/longitude coordinates. The point() function call is used to create it.

Nulls

Null is used in RedisGraph to represent an unknown or missing value.

Null is a key feature of RedisGraph's 3-valued truth table because we can't generally reason about unknown values because we don't have enough information about the compared values. The comparison null = null, for example, will return null. Similarly, because the value we're looking up is unknown, null in [1,2,3] evaluates to null.

Null cannot be saved as a property value, unlike all other scalars.

Collection types

Arrays

Arrays are collections of elements in a specific order. They can be sent in as literal or produced by functions such as collect(). Many functions that act on arrays, such as list comprehensions, are supported, as are nested arrays.

If no array element is of an unserializable type, such as graph entities or null values, arrays can be saved as property values.

Maps

Maps are collections of key-value pairs that are not ordered. The map can be accessed using dot notation if a key is a string literal. Instead, bracket notation can be used if the expression evaluates to a string literal:

$ redis-cli GRAPH.QUERY G "WITH {key1: 'stringval', key2: 10} AS map RETURN map.key1, map['key' + 2]"
1) 1) "map.key1"
  2) "map['key' + 2]"
2) 1) 1) "stringval"
      2) (integer) 10

This corresponds to how node and relationship properties can be accessed.

Property values cannot be saved as maps.

Frequently Asked Questions

What can you do using Redis?

Redis Strings is a binary-safe data format and one of Redis' most flexible building blocks. Strings, integers, floating-point values, JPEG images, serialized Ruby objects, and so on can all be stored in it.

Is Redis a database or a cache?

Redis began as a cache database but has since expanded into the primary database. Many modern apps use Redis as their primary database. Most Redis service providers, on the other hand, only offer Redis as a cache, not as a primary database.

What language is Redis written in?

Redis is a cache solution and session management system developed in ANSI C. It generates one-of-a-kind keys for storing data.

What is the usage of Redis?

Redis is a key-value store database that may be used as a NoSQL database or a memory cache store to boost performance when delivering data from system memory.

What are the ways to interact with Redis?

After the server has been installed, you can either use the Redis Client given by the Redis installation or open a command prompt and type the following command: redis-cli

Conclusion

In this article, we have learned the Data types in Redis Graph. We hope that this blog will help you understand the concept of Data types, and if you would like to learn more about it, check out our other blogs on redismongo-dBdatabase, and operational database.

Attempt our Online Mock Test Series on Coding Ninjas Studio now!

Happy Coding!

Live masterclass