aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/state/cache_key.rs
blob: a99700e99c4f939ada4d0259874ca4a2fe5d6eb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use warden_stack::redis::ToRedisArgs;

#[derive(Clone, Copy, Debug)]
pub enum CacheKey<'a> {
    ActiveRouting,
    Routing(&'a uuid::Uuid),
    Rule { id: &'a str, version: &'a str },
}

impl ToRedisArgs for CacheKey<'_> {
    fn write_redis_args<W>(&self, out: &mut W)
    where
        W: ?Sized + warden_stack::redis::RedisWrite,
    {
        let value = match self {
            CacheKey::ActiveRouting => "routing.active".into(),
            CacheKey::Routing(uuid) => format!("routing.{uuid}"),
            CacheKey::Rule { id, version } => format!("rule.{id}.{version}"),
        };

        out.write_arg(value.as_bytes());
    }
}