relay_redis/scripts.rs
1use redis::Script;
2use std::sync::OnceLock;
3
4/// A collection of static methods to load predefined Redis scripts.
5pub struct RedisScripts;
6
7impl RedisScripts {
8 /// Returns all [`Script`]s.
9 pub fn all() -> [&'static Script; 1] {
10 [Self::load_is_rate_limited()]
11 }
12
13 /// Loads the rate limiting check Redis script.
14 pub fn load_is_rate_limited() -> &'static Script {
15 static SCRIPT: OnceLock<Script> = OnceLock::new();
16 SCRIPT.get_or_init(|| Script::new(include_str!("scripts/is_rate_limited.lua")))
17 }
18}