spin_factor_outbound_redis/
lib.rs1mod host;
2
3use host::InstanceState;
4use spin_factor_outbound_networking::OutboundNetworkingFactor;
5use spin_factors::{
6 anyhow, ConfigureAppContext, Factor, PrepareContext, RuntimeFactors, SelfInstanceBuilder,
7};
8
9#[derive(Default)]
11pub struct OutboundRedisFactor {
12 _priv: (),
13}
14
15impl OutboundRedisFactor {
16 pub fn new() -> Self {
17 Self::default()
18 }
19}
20
21impl Factor for OutboundRedisFactor {
22 type RuntimeConfig = ();
23 type AppState = ();
24 type InstanceBuilder = InstanceState;
25
26 fn init(&mut self, ctx: &mut impl spin_factors::InitContext<Self>) -> anyhow::Result<()> {
27 ctx.link_bindings(spin_world::v1::redis::add_to_linker)?;
28 ctx.link_bindings(spin_world::v2::redis::add_to_linker)?;
29 Ok(())
30 }
31
32 fn configure_app<T: RuntimeFactors>(
33 &self,
34 _ctx: ConfigureAppContext<T, Self>,
35 ) -> anyhow::Result<Self::AppState> {
36 Ok(())
37 }
38
39 fn prepare<T: RuntimeFactors>(
40 &self,
41 mut ctx: PrepareContext<T, Self>,
42 ) -> anyhow::Result<Self::InstanceBuilder> {
43 let allowed_hosts = ctx
44 .instance_builder::<OutboundNetworkingFactor>()?
45 .allowed_hosts();
46 Ok(InstanceState {
47 allowed_hosts,
48 connections: spin_resource_table::Table::new(1024),
49 })
50 }
51}
52
53impl SelfInstanceBuilder for InstanceState {}