Skip to content

Instantly share code, notes, and snippets.

@gillchristian
Created June 13, 2024 07:24
Show Gist options
  • Save gillchristian/9dcbf37124872b2f34c56537f2489a05 to your computer and use it in GitHub Desktop.
Save gillchristian/9dcbf37124872b2f34c56537f2489a05 to your computer and use it in GitHub Desktop.
fn main() {
let client = redis::Client::open("redis://127.0.0.1/").expect("Failed to connect to Redis");
let mut con = client
.get_connection()
.expect("Failed to get Redis connection");
let _ = do_something(&mut con).expect("Failed to execute Redis command");
}
fn do_something(con: &mut redis::Connection) -> redis::RedisResult<()> {
let res: redis::RedisResult<()> = redis::cmd("SET").arg("my_key").arg("value").query(con);
if let Err(err) = res {
println!(
"This is the REDIS error msg: <{}>",
err.detail().unwrap_or("Unknown error")
);
return Err(err);
}
let (k1, k2): (i32, i32) = redis::pipe()
.cmd("SET").arg("key_1").arg(42) .ignore()
.cmd("SET").arg("key_2").arg(43) .ignore()
.cmd("GET").arg("key_1")
.cmd("GET").arg("key_2").query(con)?;
println!("key_1: {}, key_2: {}", k1, k2);
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment