pub struct CommandExecutor { /* private fields */ }Expand description
A thread-safe command executor that processes Redis-like commands
Manages the execution of commands against a shared memory storage, providing atomic operations and transaction support.
Implementations§
Source§impl CommandExecutor
impl CommandExecutor
Sourcepub fn new(storage: Arc<Mutex<MemoryStorage>>) -> Self
pub fn new(storage: Arc<Mutex<MemoryStorage>>) -> Self
Creates a new CommandExecutor with the given shared storage
§Arguments
storage- Thread-safe reference to the memory storage
Sourcepub fn execute_command(&self, command: Command) -> String
pub fn execute_command(&self, command: Command) -> String
Executes a single command and returns the result as a string
§Arguments
command- The command to execute
§Returns
A string containing the command’s result or error message
§Command Results
- SET - Returns “OK” on success
- GET - Returns the value or “(nil)” if not found
- DEL - Returns “1” if key was deleted, “0” if key didn’t exist
- INCR/DECR - Returns the new value after increment/decrement
- LPUSH/RPUSH - Returns the new length of the list
- LPOP/RPOP - Returns the popped value or “(nil)” if list is empty
- LLEN - Returns the length of the list
- MULTI - Returns “OK” when transaction starts
- EXEC - Returns all transaction results followed by “OK”
- DISCARD - Returns “OK” if transaction was rolled back successfully
Sourcepub fn execute_transaction(&self, commands: &[Command]) -> Vec<String>
pub fn execute_transaction(&self, commands: &[Command]) -> Vec<String>
Executes a batch of commands as part of a transaction
§Arguments
commands- A slice of commands to execute in order
§Returns
A vector of strings containing the results of each command
§Transaction Behavior
- All commands in the transaction are executed atomically
- If any command fails, the entire transaction is rolled back
- Results are collected and returned in the order of execution
Auto Trait Implementations§
impl Freeze for CommandExecutor
impl RefUnwindSafe for CommandExecutor
impl Send for CommandExecutor
impl Sync for CommandExecutor
impl Unpin for CommandExecutor
impl UnwindSafe for CommandExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more