Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created June 25, 2025 02:56
Show Gist options
  • Save kuc-arc-f/79b085ae6ce80dd3f24791625a6a1f4e to your computer and use it in GitHub Desktop.
Save kuc-arc-f/79b085ae6ce80dd3f24791625a6a1f4e to your computer and use it in GitHub Desktop.
Rust + redis , example-2
[package]
name = "redis_test"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
redis = "0.32"
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