Struct redis_protocol::codec::Resp3
source · pub struct Resp3 { /* private fields */ }Available on crate features
codec and resp3 only.Expand description
A framed codec for complete and streaming/chunked RESP3 frames.
use futures::{SinkExt, StreamExt};
use redis_protocol::{
codec::{resp3_encode_command, Resp3},
resp3::types::{BytesFrame, Resp3Frame, RespVersion},
};
use tokio::net::TcpStream;
use tokio_util::codec::Framed;
// send `HELLO 3 AUTH foo bar` then `GET foo`
async fn example() {
let socket = TcpStream::connect("127.0.0.1:6379").await.unwrap();
let mut framed = Framed::new(socket, Resp3::default());
let hello = Resp3Frame::Hello {
version: RespVersion::RESP3,
username: Some("foo".into()),
password: Some("bar".into()),
};
// or use the shorthand, but this likely only works for simple use cases
let get_foo = resp3_encode_command("GET foo");
// `Framed` implements both `Sink` and `Stream`
let _ = framed.send(hello).await.unwrap();
let response = framed.next().await.unwrap();
println!("HELLO response: {:?}", response);
let _ = framed.send(get_foo).await.unwrap();
let response = framed.next().await.unwrap();
println!("GET foo: {:?}", response);
}Trait Implementations§
source§impl Decoder for Resp3
impl Decoder for Resp3
§type Error = RedisProtocolError
type Error = RedisProtocolError
The type of unrecoverable frame decoding errors. Read more
§type Item = BytesFrame
type Item = BytesFrame
The type of decoded frames.
source§fn decode(
&mut self,
src: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>
Attempts to decode a frame from the provided buffer of bytes. Read more
Auto Trait Implementations§
impl !Freeze for Resp3
impl RefUnwindSafe for Resp3
impl Send for Resp3
impl Sync for Resp3
impl Unpin for Resp3
impl UnwindSafe for Resp3
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more