Created
June 25, 2025 02:56
-
-
Save kuc-arc-f/79b085ae6ce80dd3f24791625a6a1f4e to your computer and use it in GitHub Desktop.
Rust + redis , example-2
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}; | |
use std::{thread, time}; | |
fn main() -> RedisResult<()> { | |
// 今の時刻を取得 | |
let now = time::Instant::now(); | |
// Redis に接続 | |
let client = redis::Client::open("redis://127.0.0.1/")?; | |
let mut con = client.get_connection()?; | |
let mut position = 1; | |
let mut target = ""; | |
for i in 0..1000 { | |
let mut temp = format!("k:{}", position.to_string()); | |
target = &temp; | |
let _: () = con.set(target, "Hello, Redis!")?; | |
//println!("Key saved={}", target); | |
position += 1; | |
} | |
println!("{:?}", now.elapsed()); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment