Skip to main content
Redis is an open-source, in-memory data structure store, often referred to as a data structure server. RisingWave sinks data to Redis in the form of strings storing key-value pairs in the specified format (JSON or TEMPLATE), so a primary key must always be provided. You can test out this process on your own device by using the redis-sink demo in the integration_test directory of the RisingWave repository.

Prerequisites

Before sinking data from RisingWave to Redis, please ensure the following:
  • The Redis database you want to sink to is accessible from RisingWave.
  • Ensure you have an upstream materialized view or source in RisingWave that you can sink data from.

Syntax

Parameters

FORMAT and ENCODE options

These options should be set in FORMAT data_format ENCODE data_encode (key = 'value'), instead of the WITH clause.

Example

This section provides examples for sinking data from RisingWave to Redis, covering key-value storage, geospatial data storage, Pub/Sub messaging, and streams.

Key-value storage

This approach is suitable when you want to use Redis as a fast data store or cache, storing data as key-value pairs. Specify redis_value_type = 'string' or omit this parameter, as string is the default. Assume we create a materialized view, bhv_mv, from a source.
We can sink data from bhv_mv to Redis by creating a sink. Here, data_encode is JSON.
We can sink data from bhv_mv to Redis by creating a sink. Here, data_encode is TEMPLATE, so key_format and value_format must be defined.

Geospatial data storage

This approach allows RisingWave to store geospatial data (longitude, latitude, member) in Redis. Make sure to specify FORMAT UPSERT ENCODE TEMPLATE, redis_value_type = 'geospatial', key_format, longitude, latitude, and member. Assume we have a table t1:
We can sink geospatial data to Redis:
Now insert the geospatial data into the table t1:
You can retrieve the geospatial information from Redis:
For more information, see Geospatial indexing.

Pub/Sub messaging

This approach allows RisingWave to publish messages to Redis channels. Make sure to specify FORMAT UPSERT ENCODE TEMPLATE, redis_value_type = 'pubsub', and value_format. Specify either channel or channel_column. These two parameters are mutually exclusive. Assume we have a table t1:
We can sink data from t1 as messages to a predefined Redis Pub/Sub channel:
Alternatively, you can publish to a dynamic channel using channel_column:

Streams

Added in v2.7.0.
PREMIUM FEATUREThis is a premium feature. For a comprehensive overview of all premium features and their usage, please see RisingWave premium features.
This approach allows RisingWave to publish messages to Redis Streams. Redis Streams is a data structure that acts as an append-only log. Make sure to specify FORMAT PLAIN ENCODE TEMPLATE, redis_value_type = 'stream', key_format, and value_format. Specify either stream or stream_column. These two parameters are mutually exclusive. Assume we have a table t1:
We can sink data from t1 as messages to a predefined Redis Stream:
Alternatively, you can publish to a dynamic stream using stream_column: