Created
June 25, 2025 01:14
-
-
Save kuc-arc-f/6e1580252ba2c420127acfcf6ca21a72 to your computer and use it in GitHub Desktop.
Rust + redis , example-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "redis_test" | |
version = "0.1.0" | |
edition = "2021" | |
publish = false | |
[dependencies] | |
redis = "0.32" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use redis::{Commands, Connection, RedisResult}; | |
fn main() -> RedisResult<()> { | |
// Redis に接続 | |
let client = redis::Client::open("redis://127.0.0.1/")?; | |
let mut con = client.get_connection()?; | |
// set: キーと値を登録 | |
let _: () = con.set("name", "Hello, Redis!")?; | |
println!("Key saved!"); | |
// 確認のため get してみる | |
let val: String = con.get("name")?; | |
println!("my_key => {}", val); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment