From: Geoffrey Allott Date: Fri, 4 Aug 2023 19:49:51 +0000 (+0100) Subject: Check for notify-keyspace-events and warn if it is not enabled. Don't worry about... X-Git-Url: https://git.pointlesshacks.com/?a=commitdiff_plain;h=4f04660849868454b4a9d505258f88a98bbcb13b;p=pokerwave.git Check for notify-keyspace-events and warn if it is not enabled. Don't worry about corner cases (e.g. lists enabled for keyspace events but not strings) --- diff --git a/src/main.rs b/src/main.rs index a37720f..a773700 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use std::time::Duration; use clap::{Parser, Subcommand}; use futures::{channel::mpsc::channel, future::pending, select, FutureExt, StreamExt}; -use redis::{Client, RedisError}; +use redis::{aio::MultiplexedConnection, cmd, Client, RedisError, RedisResult}; use signal_hook::consts::signal::*; use signal_hook_async_std::Signals; use tide::{ @@ -70,6 +70,14 @@ async fn append_cache_control(mut response: Response) -> Result RedisResult<()> { + let keyspace_events: Vec = cmd("CONFIG").arg("GET").arg("notify-keyspace-events").query_async(conn).await?; + if keyspace_events.len() != 2 || !keyspace_events[1].contains("K") { + warn!("Redis \"CONFIG GET notify-keyspace-events\" returned {:?}. Keyspace events must be enabled for proper functioning.", keyspace_events); + } + Ok(()) +} + #[derive(Parser)] #[clap(version, author, about)] struct Args { @@ -160,7 +168,7 @@ async fn main() -> Result<(), tide::Error> { info!("Connecting to redis server..."); let client = Client::open(&*config.redis.addr)?; - let connection = match client.get_multiplexed_async_std_connection().await { + let mut connection = match client.get_multiplexed_async_std_connection().await { Ok(connection) => connection, Err(err) => { error!("Redis connection error: {}", err); @@ -175,6 +183,11 @@ async fn main() -> Result<(), tide::Error> { } }; + if let Err(err) = verify_keyspace_events_enabled(&mut connection).await { + error!("Redis connection error: {}", err); + continue; + } + let server = Server::new(connection, register_update_stream_tx); let handle_client_interest = handle_client_interest_subscriptions(pubsub, register_update_stream_rx);