Expand description

Abstraction of GET command.

For general information about this command, see the Redis documentation.

§Basic usage

In case of existing key Some(GetResponse) is returned.

let mut stack = Stack::default();
let clock = StandardClock::default();

let mut connection_handler = ConnectionHandler::resp2(SocketAddr::from_str("127.0.0.1:6379").unwrap());
let client = connection_handler.connect(&mut stack, Some(&clock)).unwrap();

let command = GetCommand::static_key("test_key");
let response = client.send(command).unwrap().wait().unwrap().unwrap();
assert_eq!("test_value", response.as_str().unwrap())

§Missing key (NIL/NULL response)

In case of missing key None is returned

let command = GetCommand::static_key("missing_key");
let response = client.send(command).unwrap().wait().unwrap();
assert!(response.is_none())

§Using Bytes

For best performance (instead of &str or String cloning), especially with large amounts of data, it is recommended to use Bytes.

// Using Bytes object as key
let command = GetCommand::new(Bytes::from_static("large_key".as_bytes()));

// Using response as Bytes
let command = GetCommand::new("test_key");
let response = client.send(command).unwrap().wait().unwrap().unwrap();
let _response_bytes = response.to_bytes();

§Shorthand

Client provides a shorthand method for this command.

let response = client.get("test_key").unwrap().wait().unwrap().unwrap();
assert_eq!("test_value", response.as_str().unwrap())

Structs§