Introduction to Redis Modules

Redis modules

Redis modules are an advanced feature. They allow us to implement custom data types that are specific to our use case without needing to change or update the core Redis server. Essentially, a module is a dynamic library that can be loaded into Redis at startup or on demand with the MODULE LOAD command. It’s possible to implement a Redis module using the C programming language because Redis modules expose a C API. It’s also possible to use other programming languages (such as Rust) that have C binding capabilities.

Implementing a new data type with Redis modules is a nontrivial effort. There are many popular and widely used Redis modules to solve problems such as full-text search (RediSearch), processing time series data at scale (RedisTimeSeries), native JSON support in Redis (RedisJSON), and more.

Let’s get an overview of some of the widely used Redis modules.

The RedisJSON module

It’s possible to store raw JSON data in Redis using the string data type, but this approach has limitations. One of the key issues is that it isn’t easy to manipulate specific attributes of JSON data. Instead, the whole JSON string needs to be retrieved, updated on the client-side, and written back. This is expensive because it takes up resources on the client-side as well as the network bandwidth.

The RedisJSON module provides native JSON support for Redis. Thanks to RedisJSON, we can store, manipulate, query, and work with JSON documents, just like other data structures. It supports ECMA-404 The JSON Data Interchange Standard this syntax is based on best practices and resembles JSONPath standard.

The RedisJSON module has several client libraries in different programming languages. The rueidis Go client (discussed in a previous lesson) provides support for RedisJSON in Go.

Here’s an overview of some of the common RedisJSON commands:

  • JSON.SET: Sets the JSON value to a specified path. It can also work with an existing JSON document.

  • JSON.GET: Retrieves the value from the specified path in a JSON document.

  • JSON.DEL: Deletes one or more values from the JSON document.

Here’s an example of how to use RedisJSON with the go-redis client:

Get hands-on with 1200+ tech skills courses.