resp
ModuleContents
Enums
ReplyA reply frame.Functions
encodeA command as a RESP array of bulk strings.encode_into`encode` appended to `out`.is_noscriptWhether a Redis error's code (its first word) is `NOSCRIPT`.parseOne reply from `buffer` at `offset`, advancing `offset` past what it read. `Ok(None)` when the buffer does not hold a whole frame yet (the offset may have moved past a header); an error for an unknown frame type.unwrapThe reply with every error reply in it raised: the first one found, depth first, becomes `Error::Redis`.use utopia_cache::resp::Reply;Rust
pub enum ReplyA reply frame.
use utopia_cache::resp::encode;Rust
pub fn encode<A: AsRef<[u8]>>(args: &[A]) -> Vec<u8>A command as a RESP array of bulk strings.
Rust
assert_eq!(utopia_cache::resp::encode(&[b"SET", b"foo", b"bar"]), b"*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n");use utopia_cache::resp::encode_into;Rust
pub fn encode_into<A: AsRef<[u8]>>(out: &mut Vec<u8>, args: &[A])encode appended to out.
use utopia_cache::resp::is_noscript;Rust
pub fn is_noscript(error: &str) -> boolWhether a Redis error's code (its first word) is NOSCRIPT.
Rust
assert!(utopia_cache::resp::is_noscript("NOSCRIPT No matching script. Please use EVAL."));
assert!(!utopia_cache::resp::is_noscript("ERR user set key to \"NOSCRIPT\""));use utopia_cache::resp::parse;Rust
pub fn parse(buffer: &[u8], offset: &mut usize) -> Result<Option<Reply>>One reply from buffer at offset, advancing offset past what it
read. Ok(None) when the buffer does not hold a whole frame yet (the
offset may have moved past a header); an error for an unknown frame type.
Rust
use utopia_cache::resp::{parse, Reply};
let mut offset = 0;
assert_eq!(parse(b"*2\r\n:1\r\n$1\r\nx\r\n", &mut offset)?, Some(Reply::Array(vec![Reply::Int(1), Reply::Str(b"x".to_vec())])));
assert_eq!(offset, 15);
assert_eq!(parse(b"$5\r\nhel", &mut 0)?, None);use utopia_cache::resp::unwrap;Rust
pub fn unwrap(reply: Reply) -> Result<Reply>The reply with every error reply in it raised: the first one found,
depth first, becomes Error::Redis.
Rust
use utopia_cache::resp::{unwrap, Reply};
assert!(unwrap(Reply::Array(vec![Reply::Int(1), Reply::Error(b"NOAUTH".to_vec())])).is_err());
assert_eq!(unwrap(Reply::Int(42))?, Reply::Int(42));