Expand description
Abstraction of HSET command.
For general information about this command, see the Redis documentation.
§Using command object
use embedded_redis::commands::hset::HashSetCommand;
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 = HashSetCommand::new("my_hash", "color", "green");
let response = client.send(command).unwrap().wait().unwrap();
// Returns the number of added fields
assert_eq!(1, response)
§Setting multiple fields at once
let command = HashSetCommand::multiple("my_hash".into(), [
("color".into(), "green".into()),
("material".into(), "stone".into())
]);
let response = client.send(command).unwrap().wait().unwrap();
// Returns the number of added fields
assert_eq!(2, response)
§Shorthand
Client provides a shorthand method for this command.
// Using &str arguments
let _ = client.hset("hash", "field", "value");
// Using String arguments
let _ = client.hset("hash".to_string(), "field".to_string(), "value".to_string());
// Using Bytes arguments
let _ = client.hset(Bytes::from_static(b"hash"), Bytes::from_static(b"field"), Bytes::from_static(b"value"));
Structs§
- Hash
SetCommand - Abstraction of HSET command