1pub mod error;
14pub mod presence;
15pub mod typing;
16pub mod cache;
17pub mod pubsub;
18pub mod locking;
19pub mod job;
20pub mod job_queue;
21pub mod worker_pool;
22
23pub use error::{RedisError, Result};
25pub use presence::PresenceManager;
26pub use typing::TypingManager;
27pub use cache::CacheManager;
28pub use pubsub::PubSubManager;
29pub use locking::{LockManager, LockGuard};
30pub use job::{Job, QueuedJob};
31pub use job_queue::{JobQueue, QueueError, QueueStats};
32pub use worker_pool::{
33 JobExecutor, JobStore, WorkerPool, WorkerPoolConfig,
34 WorkerError, StoreError, ExecutorError,
35};
36
37#[derive(Debug, Clone)]
39pub struct RedisConfig {
40 pub url: String,
42
43 pub presence_ttl_seconds: u64,
45
46 pub typing_ttl_seconds: u64,
48
49 pub cache_ttl_seconds: u64,
51}
52
53impl Default for RedisConfig {
54 fn default() -> Self {
55 Self {
56 url: "redis://127.0.0.1:6379".to_string(),
57 presence_ttl_seconds: 300,
58 typing_ttl_seconds: 5,
59 cache_ttl_seconds: 300,
60 }
61 }
62}
63
64impl RedisConfig {
65 pub fn new(url: impl Into<String>) -> Self {
67 Self {
68 url: url.into(),
69 ..Default::default()
70 }
71 }
72
73 pub fn with_presence_ttl(mut self, seconds: u64) -> Self {
75 self.presence_ttl_seconds = seconds;
76 self
77 }
78
79 pub fn with_typing_ttl(mut self, seconds: u64) -> Self {
81 self.typing_ttl_seconds = seconds;
82 self
83 }
84
85 pub fn with_cache_ttl(mut self, seconds: u64) -> Self {
87 self.cache_ttl_seconds = seconds;
88 self
89 }
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95
96 #[test]
97 fn test_config_builder() {
98 let config = RedisConfig::new("redis://localhost:6379")
99 .with_presence_ttl(600)
100 .with_typing_ttl(10)
101 .with_cache_ttl(1800);
102
103 assert_eq!(config.url, "redis://localhost:6379");
104 assert_eq!(config.presence_ttl_seconds, 600);
105 assert_eq!(config.typing_ttl_seconds, 10);
106 assert_eq!(config.cache_ttl_seconds, 1800);
107 }
108}