CommandExecutor

Struct CommandExecutor 

Source
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

Source

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
Source

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
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.