redis_imitate/config/
config.rs

1//! # Configuration Module
2//! 
3//! Provides configuration settings for the Redis-like server, 
4//! with serialization support through serde.
5
6use serde::{Deserialize, Serialize};
7
8/// Server configuration settings
9///
10/// Holds all configurable parameters for the Redis-like server instance.
11/// Supports serialization and deserialization through serde.
12#[derive(Debug, Clone, Deserialize, Serialize)]
13pub struct Config {
14   /// Server host address
15   /// Default: "0.0.0.0" (binds to all network interfaces)
16   pub host: String,
17
18   /// Server port number
19   /// Default: 6379 (standard Redis port)
20   pub port: u16,
21
22   /// Maximum number of simultaneous client connections
23   /// Default: 1000
24   pub max_connections: usize,
25
26   /// Maximum memory usage in bytes
27   /// Default: 1GB (1024*1024*1024 bytes)
28   pub max_memory: usize,
29}
30
31impl Config {
32   /// Creates a new Config instance with default values
33   ///
34   /// # Default Values
35   ///
36   /// * host: "0.0.0.0" - Binds to all network interfaces
37   /// * port: 6379 - Standard Redis port
38   /// * max_connections: 1000 - Maximum concurrent connections
39   /// * max_memory: 1GB - Maximum memory usage
40   ///
41   /// # Returns
42   ///
43   /// A new Config instance initialized with default values
44   pub fn new() -> Self {
45       Config {
46           host: "0.0.0.0".to_string(),
47           port: 6379,
48           max_connections: 1000,
49           max_memory: 1024 * 1024 * 1024,  // 1GB
50       }
51   }
52}