I'm putting together a command line utility that can monitor multiple instances of Redis concurrently using async/await. This works great, but I'm stumped as to how I would go about determining which connection a given bit of data is coming from.
Here's just the main routine for brevity.
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = std::env::args().skip(1).collect::<Vec<_>>();
let mut connections = SelectAll::new();
for arg in &args {
let mut con = get_connection(arg.parse().unwrap()).await?;
con.send(resp_array!["MONITOR"]).await?;
let con = con.skip(1);
connections.push(con);
}
// What should I wrap/implement so I can deliver context in
// addition to the message itself?
while let Some(v) = connections.next().await {
println!("{:?}", v);
}
Ok(())
}
How would I go about wrapping this data such that I could get not just the data itself but context as to which connection it came from?
As it happens, I can solve this issue by just parsing the MONITOR
messages as they contain the IP/port information I would need, but I'm curious as to how I would go about this generally.
If it helps the RespConnection
uses a Framed
TcpStream to parse the RESP
messages.