Rust: 删除Redis数据
文件夹的结构
$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
└── debug
[package]
name = "redis_delete"
version = "0.1.0"
edition = "2018"
#
[dependencies.redis]
version = "*"
[dependencies]
tokio = { version = "0.2", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
// --------------------------------------------------------------------
/*
redis_delete/src/main.rs
Jul/22/2020
*/
// --------------------------------------------------------------------
use std::env;
extern crate redis;
use redis::{Commands};
// --------------------------------------------------------------------
fn main() -> Result<(), Box<dyn std::error::Error>> {
eprintln! ("*** 開始 ***");
let args: Vec<_> = env::args().collect();
let key_in = &args[1];
eprintln! ("{}",key_in);
let client = redis::Client::open("redis://localhost/").expect("url error");
let mut conn = client.get_connection().expect("connect error");
// let key_in = "t1853";
let result: i32 = conn.del(key_in).unwrap();
println!("削除結果: 1 => 成功, 0 => 失敗");
println!("del result for myKey: {}", result);
eprintln! ("*** 終了 ***");
Ok(())
}
// --------------------------------------------------------------------
编译
cargo build
执行
cargo run t1856