A simple Redis message handler using TinyGo and Fermyon Spin to demonstrate event-driven WebAssembly applications.
This application listens for messages published to a Redis channel and processes them using a WebAssembly component compiled with TinyGo.
- Spin CLI
- Go 1.20.5+
- TinyGo 0.33.0+
- Docker (for running Redis)
# Install Spin
curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash
sudo mv ./spin /usr/local/bin/
# Install/upgrade Go
brew update && brew upgrade go
# Install TinyGo
brew tap tinygo-org/tools
brew install tinygodocker run --name redis-server -d -p 6379:6379 redisspin build --upYou should see:
Active Channels on redis://127.0.0.1:6379:
redis://127.0.0.1:6379:hello-messages: [hello-message-handler]
In another terminal, publish a message:
docker exec -it redis-server redis-cli
127.0.0.1:6379> PUBLISH hello-messages "Hello from Redis!"The message will appear in your Spin application logs.
main.go- Message handler implementationspin.toml- Spin application configurationmain.wasm- Compiled WebAssembly binary (generated)
The app listens to Redis at 127.0.0.1:6379 on the hello-messages channel. You can modify these settings in spin.toml.
Read the full writeup: Taking TinyGo for a Spin
Anita Bendelja (@anitabee)