spin_key_value_redis/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
mod store;

use serde::Deserialize;
use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore;
use store::KeyValueRedis;

/// A key-value store that uses Redis as the backend.
#[derive(Default)]
pub struct RedisKeyValueStore {
    _priv: (),
}

impl RedisKeyValueStore {
    /// Creates a new `RedisKeyValueStore`.
    pub fn new() -> Self {
        Self::default()
    }
}

/// Runtime configuration for the Redis key-value store.
#[derive(Deserialize)]
pub struct RedisKeyValueRuntimeConfig {
    /// The URL of the Redis server.
    url: String,
}

impl MakeKeyValueStore for RedisKeyValueStore {
    const RUNTIME_CONFIG_TYPE: &'static str = "redis";

    type RuntimeConfig = RedisKeyValueRuntimeConfig;

    type StoreManager = KeyValueRedis;

    fn make_store(
        &self,
        runtime_config: Self::RuntimeConfig,
    ) -> anyhow::Result<Self::StoreManager> {
        KeyValueRedis::new(runtime_config.url)
    }
}