The Spin Redis trigger

Spin applications can be triggered by a new message on a Redis channel. Spin will connect to a configured Redis instance and will invoke components for new messages on the configured channels.

See the Rust language guide for details on using Rust to build Redis components.

The Redis instance address is specified in the application trigger:

# spin.toml
trigger = { type = "redis", address = "redis://localhost:6379" }

We are exploring adding authentication for connecting to Redis and adding host support for connecting to Redis databases, from components, which would allow using the key/value store and publishing messages to channels.

Then, all components in the application are triggered when new messages are published to channels in the instance. Configuring the channel is done by setting the channel field in the component trigger configuration.

channel = "messages"

The WebAssembly Interface

The Redis trigger is built on top of the WebAssembly component model. The current interface is defined using the WebAssembly Interface (WIT) format, and is a function that takes the message payload as its only parameter:

// wit/ephemeral/spin-redis.wit

// The message payload.
type payload = list<u8>

// The entry point for a Redis handler.
handle-redis-message: function(msg: payload) -> expected<_, error>

The interface might change in the future to add the Redis instance and message channel as arguments to the function.

This is the function that all Redis components must implement, and which is used by the Spin Redis executor when instantiating and invoking the component. This interface (spin-redis.wit) can be directly used together with the Bytecode Alliance wit-bindgen project to build a component that the Spin HTTP executor can invoke. This is exactly how the Rust SDK for Spin is built, and, as more languages add support for the component model, how we plan to add support for them as well.

We are exploring a compatibility layer (similar to Wagi) so languages that do not have support for the component model can be used to build Redis components for Spin.

Did we miss something?

Let us know how we can improve this project, or contribute an edit to this page. We really appreciate your feedback, to help us build better tools.