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