diff --git a/Cargo.toml b/Cargo.toml index dde9d48..0792ef5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,3 +60,9 @@ once_cell = "1" [build-dependencies] cc="*" + +[profile.release] +lto = true +opt-level = "z" +codegen-units = 1 +strip = "debuginfo" diff --git a/src/main.rs b/src/main.rs index 926715b..34c7fa6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use std::time::Duration; use tokio::time::{interval}; use crate::app::AppState::Closed; use crate::bus::{publish_msg, try_take_msg, Message}; +use crate::tui::TerminalBackEnd; #[tokio::main] async fn main() -> Result<()> { @@ -57,7 +58,9 @@ async fn main() -> Result<()> { } } - render(App::new(db_config), app_config).await?; + let terminal = tui::init()?; + let app = App::new(db_config); + let app_result = run(app, terminal, app_config).await; if let Err(e) = tui::restore() { eprintln!( @@ -66,11 +69,14 @@ async fn main() -> Result<()> { ); } + if let Err(e) = app_result { + eprintln!("{}", e); + } + Ok(()) } -async fn render(mut app: App, config: Configuration) -> Result<()> { - let mut terminal = tui::init()?; +async fn run(mut app: App, mut terminal: TerminalBackEnd, config: Configuration) -> Result<()> { let fps = cmp::min(config.fps.unwrap_or(30) as usize, 60); let delay_millis = 1000 / fps; let delay_duration = Duration::from_millis(delay_millis as u64); @@ -144,45 +150,4 @@ async fn render(mut app: App, config: Configuration) -> Result<()> { } app.state = Closed; Ok(()) -} - -// async fn handle_events(app_arc: Arc>) -> Result<()> { -// loop { -// let app_read_guard = app_arc.read().await; -// if !app_read_guard.health() { -// break; -// } -// if app_read_guard.state == AppState::Preparing { -// let mut context_write_guard = app_read_guard.context.write().await; -// context_write_guard.on_app_event(AppEvent::Init).await?; -// drop(context_write_guard); -// drop(app_read_guard); -// let mut app_write_guard = app_arc.write().await; -// app_write_guard.state = AppState::Running; -// continue; -// } -// let event_result = app_read_guard.input.receiver().try_recv(); -// drop(app_read_guard); -// if let Ok(input_event) = event_result { -// if let InputEvent::Input(event) = input_event { -// if let Event::Key(key_event) = event { -// if key_event.kind == KeyEventKind::Press { -// if key_event.modifiers == KeyModifiers::CONTROL && key_event.code == KeyCode::Char('c') { -// let mut app_write_guard = app_arc.write().await; -// app_write_guard.state = AppState::Closing; -// drop(app_write_guard); -// } else { -// let app_read_guard = app_arc.read().await; -// let mut context_write_guard = app_read_guard.context.write().await; -// let _ = context_write_guard.handle_key_event(key_event).await?; -// drop(context_write_guard); -// drop(app_read_guard); -// } -// } -// } -// } -// } -// } -// -// Ok(()) -// } \ No newline at end of file +} \ No newline at end of file diff --git a/src/redis_opt.rs b/src/redis_opt.rs index 6e52f81..b2dcefe 100644 --- a/src/redis_opt.rs +++ b/src/redis_opt.rs @@ -37,10 +37,19 @@ where }); Ok(()) } else { - Err(anyhow!("")) + Ok(()) } } +/// ``` +/// let value = async_redis_opt(|operations| async move { +/// Ok(operations.get::<_, String>("key_to_get").await?) +/// }).await?; +/// +/// let value: String = async_redis_opt(|operations| async move { +/// Ok(operations.get("key_to_get").await?) +/// }).await?; +/// ``` pub async fn async_redis_opt(opt: F) -> Result where F: FnOnce(RedisOperations) -> FUT, @@ -50,7 +59,7 @@ where if let Some(c) = x { opt(c.clone()).await } else { - Err(anyhow!("")) + Err(anyhow!("redis operations not initialized")) } } @@ -532,6 +541,19 @@ impl RedisOperations { } } + pub async fn xlen(&self, key: K) -> Result { + if self.is_cluster() { + let pool = &self.cluster_pool.clone().context("should be cluster")?; + let mut connection = pool.get().await?; + let v: usize = connection.xlen(key).await?; + Ok(v) + } else { + let mut connection = self.pool.get().await?; + let v: usize = connection.xlen(key).await?; + Ok(v) + } + } + // pub async fn sscan(&self, key: K) -> Result> { // if self.is_cluster() { // let pool = &self.cluster_pool.clone().context("should be cluster")?; diff --git a/src/tabs/explorer.rs b/src/tabs/explorer.rs index 99d89f7..aa13dc6 100644 --- a/src/tabs/explorer.rs +++ b/src/tabs/explorer.rs @@ -910,6 +910,7 @@ impl ExplorerTab { "hash" => Ok(op.hlen(key_name_clone).await?), "set" => Ok(op.scard(key_name_clone).await?), "zset" => Ok(op.zcard(key_name_clone).await?), + "stream" => Ok(op.xlen(key_name_clone).await?), _ => Ok(0) } }).await; @@ -1189,7 +1190,7 @@ impl Listenable for ExplorerTab { fn on_app_event(&mut self, _app_event: AppEvent) -> Result<()> { if _app_event == AppEvent::Init { if let Some(first_line) = self.get_filter_text() { - self.do_scan(first_line.clone())?; + self.do_scan(first_line)?; } } if _app_event == AppEvent::Reset { @@ -1197,7 +1198,7 @@ impl Listenable for ExplorerTab { self.show_filter = false; self.filter_text_area = TextArea::default(); if let Some(first_line) = self.get_filter_text() { - self.do_scan(first_line.clone())?; + self.do_scan(first_line)?; } } Ok(())