mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-24 04:59:41 +00:00
add rust lang to repo by add assets/mini-redis
This commit is contained in:
31
zh-CN/assets/mini-redis/examples/pub.rs
Normal file
31
zh-CN/assets/mini-redis/examples/pub.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//! Publish to a redis channel example.
|
||||
//!
|
||||
//! A simple client that connects to a mini-redis server, and
|
||||
//! publishes a message on `foo` channel
|
||||
//!
|
||||
//! You can test this out by running:
|
||||
//!
|
||||
//! cargo run --bin mini-redis-server
|
||||
//!
|
||||
//! Then in another terminal run:
|
||||
//!
|
||||
//! cargo run --example sub
|
||||
//!
|
||||
//! And then in another terminal run:
|
||||
//!
|
||||
//! cargo run --example pub
|
||||
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use mini_redis::{client, Result};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Open a connection to the mini-redis address.
|
||||
let mut client = client::connect("127.0.0.1:6379").await?;
|
||||
|
||||
// publish message `bar` on channel foo
|
||||
client.publish("foo", "bar".into()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user