Rust: Redis のデータを削除 (Delete)
フォルダー構造
$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
└── debug
Cargo.toml
[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"
src/main.rs
// --------------------------------------------------------------------
/*
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
Author And Source
この問題について(Rust: Redis のデータを削除 (Delete)), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/345bddfd21b25882b9ee著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .