spin_key_value_redis/
lib.rs

1mod store;
2
3use serde::Deserialize;
4use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore;
5use store::KeyValueRedis;
6
7/// A key-value store that uses Redis as the backend.
8#[derive(Default)]
9pub struct RedisKeyValueStore {
10    _priv: (),
11}
12
13impl RedisKeyValueStore {
14    /// Creates a new `RedisKeyValueStore`.
15    pub fn new() -> Self {
16        Self::default()
17    }
18}
19
20/// Runtime configuration for the Redis key-value store.
21#[derive(Deserialize)]
22pub struct RedisKeyValueRuntimeConfig {
23    /// The URL of the Redis server.
24    url: String,
25}
26
27impl MakeKeyValueStore for RedisKeyValueStore {
28    const RUNTIME_CONFIG_TYPE: &'static str = "redis";
29
30    type RuntimeConfig = RedisKeyValueRuntimeConfig;
31
32    type StoreManager = KeyValueRedis;
33
34    fn make_store(
35        &self,
36        runtime_config: Self::RuntimeConfig,
37    ) -> anyhow::Result<Self::StoreManager> {
38        KeyValueRedis::new(runtime_config.url)
39    }
40}