pub struct MemoryStorage { /* private fields */ }Expand description
Main storage engine implementing Redis-like functionality
Provides thread-safe storage with transaction support and caching. All keys are case-insensitive and stored in lowercase.
Implementations§
Source§impl MemoryStorage
impl MemoryStorage
Sourcepub fn save_snapshot(&self, path: &str) -> Result<()>
pub fn save_snapshot(&self, path: &str) -> Result<()>
Sourcepub fn load_snapshot(&mut self, path: &str) -> Result<()>
pub fn load_snapshot(&mut self, path: &str) -> Result<()>
Sourcepub fn start_transaction(&mut self)
pub fn start_transaction(&mut self)
Starts a new transaction
Creates a new transaction layer that will track changes until committed or rolled back.
Sourcepub fn commit_transaction(&mut self) -> Result<Vec<String>, String>
pub fn commit_transaction(&mut self) -> Result<Vec<String>, String>
Commits the current transaction
§Returns
Ok(Vec<String>)- Results of operations in the transactionErr(String)- Error message if no transaction is active
Sourcepub fn rollback_transaction(&mut self) -> Result<(), String>
pub fn rollback_transaction(&mut self) -> Result<(), String>
Rolls back the current transaction
§Returns
Ok(())- Transaction successfully rolled backErr(String)- Error message if no transaction is active
Sourcepub fn set(&mut self, key: String, value: String)
pub fn set(&mut self, key: String, value: String)
Sets a key-value pair in the storage
If a transaction is active, the change is recorded in the current transaction layer. Otherwise, it’s applied directly to the main storage. The value is also cached.
§Arguments
key- The key (case-insensitive)value- The value to store
Sourcepub fn get(&mut self, key: &str) -> Option<String>
pub fn get(&mut self, key: &str) -> Option<String>
Retrieves a value by its key
Checks the cache first, then active transactions from newest to oldest, finally falling back to main storage. Found values are cached for future access.
§Arguments
key- The key to look up (case-insensitive)
§Returns
Some(String)- The value if foundNone- If the key doesn’t exist
Sourcepub fn del(&mut self, key: &str) -> bool
pub fn del(&mut self, key: &str) -> bool
Deletes a key-value pair from storage
In a transaction, marks the key for deletion. Otherwise, removes it from main storage immediately. Also removes the key from cache if it existed.
§Arguments
key- The key to delete (case-insensitive)
§Returns
true if the key existed and was marked for deletion or removed