Check for notify-keyspace-events and warn if it is not enabled. Don't worry about...
authorGeoffrey Allott <geoffrey@allott.email>
Fri, 4 Aug 2023 19:49:51 +0000 (20:49 +0100)
committerGeoffrey Allott <geoffrey@allott.email>
Fri, 4 Aug 2023 19:49:51 +0000 (20:49 +0100)
src/main.rs

index a37720fdb789f2601d6493e0597e370927ecaf3f..a773700a2ba82fc676240fd17ed1f93986c7d221 100644 (file)
@@ -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<Response, tide::
     Ok(response)
 }
 
+async fn verify_keyspace_events_enabled(conn: &mut MultiplexedConnection) -> RedisResult<()> {
+    let keyspace_events: Vec<String> = 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);