This commit is contained in:
Conrad Irwin 2024-01-26 16:36:49 -07:00
parent 5db7e8f89e
commit 8e5df27db4
3 changed files with 54 additions and 1 deletions

32
Cargo.lock generated
View file

@ -1474,6 +1474,7 @@ dependencies = [
"prometheus",
"prost 0.8.0",
"rand 0.8.5",
"redis",
"reqwest",
"rpc",
"scrypt",
@ -1586,7 +1587,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
dependencies = [
"bytes 1.5.0",
"futures-core",
"memchr",
"pin-project-lite 0.2.13",
"tokio",
"tokio-util 0.7.9",
]
[[package]]
@ -5910,6 +5915,27 @@ dependencies = [
"workspace",
]
[[package]]
name = "redis"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c580d9cbbe1d1b479e8d67cf9daf6a62c957e6846048408b80b43ac3f6af84cd"
dependencies = [
"async-trait",
"bytes 1.5.0",
"combine",
"futures-util",
"itoa",
"percent-encoding",
"pin-project-lite 0.2.13",
"ryu",
"sha1_smol",
"socket2 0.4.9",
"tokio",
"tokio-util 0.7.9",
"url",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
@ -6948,6 +6974,12 @@ dependencies = [
"digest 0.10.7",
]
[[package]]
name = "sha1_smol"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.9.9"

View file

@ -22,6 +22,7 @@ live_kit_server = { path = "../live_kit_server" }
text = { path = "../text" }
rpc = { path = "../rpc" }
util = { path = "../util" }
redis = { version = "0.24.0", features = ["tokio-comp"] }
anyhow.workspace = true
async-tungstenite = "0.16"

View file

@ -2,11 +2,13 @@ use anyhow::anyhow;
use axum::{routing::get, Extension, Router};
use collab::{db, env, executor::Executor, AppState, Config, MigrateConfig, Result};
use db::Database;
use futures::StreamExt;
use redis::aio::PubSub;
use std::{
env::args,
net::{SocketAddr, TcpListener},
path::Path,
sync::Arc,
sync::{Arc, OnceLock},
};
use tokio::signal::unix::SignalKind;
use tracing_log::LogTracer;
@ -15,8 +17,26 @@ use util::ResultExt;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
// static REDIS_PUBSUB: OnceLock<PubSub> = OnceLock::new();
#[tokio::main]
async fn main() -> Result<()> {
let client = redis::Client::open("redis://127.0.0.1:6379").unwrap();
let con = client.get_async_connection().await.unwrap();
let mut pubsub = con.into_pubsub();
// let pubsub = &mut REDIS_PUBSUB.get_or_init(|| {
// pubsub
// });
tokio::spawn(async move {
pubsub.subscribe("foo").await.unwrap();
let mut messages = pubsub.on_message();
loop {
let msg = messages.next().await.unwrap();
println!("Received: {:?}", msg);
}
});
if let Err(error) = env::load_dotenv() {
eprintln!(
"error loading .env.toml (this is expected in production): {}",