Module hget

Source
Expand description

Abstraction of HGET command.

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

§Using command object

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();
client.hset("test_hash", "color", "green").unwrap().wait().unwrap();

let command = HashGetCommand::new("test_hash", "color");
let response = client.send(command).unwrap().wait().unwrap().unwrap();

assert_eq!("green", response.as_str().unwrap())

§Missing key or field

In case key or field is missing. None is returned.

let command = HashGetCommand::new("not_existing", "field");
let response = client.send(command).unwrap().wait().unwrap();

assert!(response.is_none())

§Shorthand

Client provides a shorthand method for this command.

// Using &str arguments
let response = client.hget("hash_key", "hash_field").unwrap().wait().unwrap().unwrap();
assert_eq!("example", response.as_str().unwrap());

// Using String arguments
let _ = client.hget("hash_key".to_string(), "hash_field".to_string());

// Using Bytes arguments
let _ = client.hget(Bytes::from_static(b"hash_key"), Bytes::from_static(b"hash_field"));

Structs§

HashGetCommand
Abstraction for HGET command