Skip to main content

cpex_session_valkey/
factory.rs

1// Location: ./builtins/session/valkey/src/factory.rs
2// Copyright 2026
3// SPDX-License-Identifier: Apache-2.0
4// Authors: Fred Araujo
5//
6// `ValkeySessionStoreFactory` — the `SessionStoreFactory` that lets the
7// apl-cpex visitor build a `ValkeySessionStore` from a
8// `global.apl.session_store: { kind: valkey, ... }` block. Mirrors the
9// PDP factories (CelPdpFactory, CedarDirectPdpFactory).
10
11use std::sync::Arc;
12
13use apl_cpex::{SessionStore, SessionStoreFactory};
14
15use crate::config::ValkeyConfig;
16use crate::store::ValkeySessionStore;
17
18/// The `kind:` discriminator this factory builds. Part of the public
19/// surface — it is the string operators write in their config.
20pub const KIND: &str = "valkey";
21
22/// Factory the host registers via `AplOptions.session_store_factories`.
23#[derive(Default)]
24pub struct ValkeySessionStoreFactory;
25
26impl ValkeySessionStoreFactory {
27    pub fn new() -> Self {
28        Self
29    }
30}
31
32impl SessionStoreFactory for ValkeySessionStoreFactory {
33    fn kind(&self) -> &str {
34        KIND
35    }
36
37    fn build(
38        &self,
39        config: &serde_yaml::Value,
40    ) -> Result<Arc<dyn SessionStore>, Box<dyn std::error::Error + Send + Sync>> {
41        let cfg = ValkeyConfig::from_value(config)?;
42        let store = ValkeySessionStore::from_config(&cfg)?;
43        Ok(Arc::new(store))
44    }
45}