2 use mini_redis::client;
18 let (manager_tx, mut manager_rx) = mpsc::channel(32);
20 let manager = tokio::spawn(async move {
21 // Establish a connection to the server
22 let mut client = client::connect("127.0.0.1:6379").await.unwrap();
24 while let Some(cmd) = manager_rx.recv().await {
26 Command::Get { key } => { client.get(&key).await.unwrap(); }
27 Command::Set { key, val } => { client.set(&key, val).await.unwrap(); }
32 let manager_tx2 = manager_tx.clone();
33 // Spawn two tasks, one gets a key, the other sets a key
34 let t1 = tokio::spawn(async move {
35 manager_tx.send(Command::Get { key: "hello".to_string() }).await.unwrap();
38 let t2 = tokio::spawn(async move {
39 manager_tx2.send(Command::Set { key: "hello".to_string(), val: "bar".into() }).await.unwrap();
44 manager.await.unwrap();