So I call a database (Redis) and perform a GET command using Rust and even store the value in a variable, the problem is that the variable is inside the method block. -Not to mention the variable name is specified in the method itself and not determined when called. Is there a way where I could bring the variable out so I can use it for things while the method's return is preoccupied with Result?
pub fn get(key:String) -> redis::RedisResult<()>
{
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut con = client.get_connection()?;
let variable_name:String = redis::cmd("GET").arg(key).query(&mut con)?;
println!("Value: {:?}", variable_name);
Ok(())
}
To get the result of a fallible operation, you must use either .unwrap(), the question mark, or some other method for handling the error. There's a chapter in the book about this