use crate::{
error::RedisError,
types::{RedisConfig, RedisValue},
utils as client_utils,
};
use futures::Stream;
use std::fmt;
mod parser;
mod utils;
#[derive(Clone, Debug)]
pub struct Command {
pub command: String,
pub args: Vec<RedisValue>,
pub timestamp: f64,
pub db: u8,
pub client: String,
}
impl PartialEq for Command {
fn eq(&self, other: &Self) -> bool {
client_utils::f64_eq(self.timestamp, other.timestamp)
&& self.client == other.client
&& self.db == other.db
&& self.command == other.command
&& self.args == other.args
}
}
impl Eq for Command {}
impl fmt::Display for Command {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{:.6} [{} {}] \"{}\"",
self.timestamp, self.db, self.client, self.command
)?;
for arg in self.args.iter() {
write!(f, " \"{}\"", arg.as_str().unwrap_or("unknown".into()))?;
}
Ok(())
}
}
pub async fn run(config: RedisConfig) -> Result<impl Stream<Item = Command>, RedisError> {
utils::start(config).await
}