Skip to content

Instantly share code, notes, and snippets.

@badboy
Created March 16, 2018 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badboy/b64026f239df5279974da88a14d9fe41 to your computer and use it in GitHub Desktop.
Save badboy/b64026f239df5279974da88a14d9fe41 to your computer and use it in GitHub Desktop.
extern crate redis;
use std::error::Error;
use redis::{Commands};
fn do_redis_code() -> redis::RedisResult<()> {
let client = try!(redis::Client::open("redis://127.0.0.1/"));
let con = try!(client.get_connection());
let () = redis::cmd("HMSET").arg("a").arg(&["fa", "1", "fb", "2"]).query(&con).unwrap();
let data : Vec<String> = con.hget("a", &["fa", "fb"]).unwrap();
println!("Found: {:?}", data);
let data : Vec<String> = con.hget("a", &["fa", "fc"]).unwrap();
println!("Found: {:?}", data);
let data : Vec<String> = con.hget("a", &["fd", "fe"]).unwrap();
println!("Found: {:?}", data);
Ok(())
}
fn main() {
// at this point the errors are fatal, let's just fail hard.
match do_redis_code() {
Err(err) => {
println!("Could not execute example:");
println!(" {}: {}", err.category(), err.description());
}
Ok(()) => {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment