-
Notifications
You must be signed in to change notification settings - Fork 302
Async Redis trigger #3435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async Redis trigger #3435
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "redis-async-trigger-smoke-test" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| anyhow = "1" | ||
| bytes = "1" | ||
| wit-bindgen = "0.54" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| use std::str::from_utf8; | ||
|
|
||
| const KV_KEY: &str = "message"; | ||
|
|
||
| wit_bindgen::generate!({ | ||
| path: "../../../../wit", | ||
| world: "spin:up/redis-trigger@3.7.0", | ||
| generate_all, | ||
| }); | ||
|
|
||
| struct Guest; | ||
|
|
||
| impl exports::spin::redis::inbound_redis::Guest for Guest { | ||
| async fn handle_message(message: Vec<u8>) -> Result<(), spin::redis::redis::Error> { | ||
| // Do some async stuff to prove it works | ||
| let kv = spin::key_value::key_value::Store::open("default".to_string()).await.expect("should have had access to default KV store"); | ||
| kv.set(KV_KEY.to_string(), message.clone()).await.expect("should have set KV entry"); | ||
| let message = kv.get(KV_KEY.to_string()).await.expect("should have read KV entry").expect("KV entry should have existed"); | ||
|
|
||
| println!("Got message: '{}'", from_utf8(&message).unwrap_or("<MESSAGE NOT UTF8>")); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| export!(Guest); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| spin_manifest_version = 2 | ||
|
|
||
| [application] | ||
| authors = ["Spin Framework Contributors"] | ||
| description = "A simple redis application that exercises the Rust SDK in the current branch" | ||
| name = "redis-async-trigger-smoke-test" | ||
| version = "1.0.0" | ||
|
|
||
| [application.trigger.redis] | ||
| address = "redis://localhost:%{port=6379}" | ||
|
|
||
| [[trigger.redis]] | ||
| channel = "my-channel" | ||
| component = "hello" | ||
|
|
||
| [component.hello] | ||
| source = "%{source=redis-async-trigger-smoke-test}" | ||
| key_value_stores = ["default"] | ||
| [component.hello.build] | ||
| command = "cargo build --target wasm32-wasip2 --release" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,12 @@ world http-trigger { | |
| export wasi:http/handler@0.3.0-rc-2026-03-15; | ||
| } | ||
|
|
||
| /// The full world of a guest targeting a redis-trigger | ||
| world redis-trigger { | ||
| include platform; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a quick note that this one line is super valuable. As I work on updating spin-go-sdk to work with modern Spin, I noticed that the existing
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The WIT worlds are kind of untrue: we link everything unconditinally in the factors. My guess is that if a v1 Redis trigger used WASI P2 HTTP then it would work despite what the WIT world says... |
||
| export spin:redis/inbound-redis@3.0.0; | ||
| } | ||
|
|
||
| /// The imports needed for a guest to run on a Spin host | ||
| world platform { | ||
| include wasi:cli/imports@0.2.6; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my other comment in this review, we should make sure we've added all the other
spin:up/platformstuff to the linker, not just the oldfermyon:spin/platformstuff. I don't think there's an easy way to do that only for theV3case, so we'd be givingV1components access to all that stuff, too, but that's not a huge problem, I'd imagine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe
RuntimeFactors(via the base trigger implementation) takes care of that. My test shows we have access to async KV (a very recent addition) and I didn't need to do anything to make that work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I just realized the error I was getting was from
componentize-gorather than Spin, meaning you can ignore what I said above. Sorry for the noise!