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 = BytesFrame::Hello {
version: RespVersion::RESP3,
auth: Some(("foo".into(), "bar".into())),
setname: None,
};
// 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);
}Implementations§
Trait Implementations§
Source§impl Decoder for Resp3
impl Decoder for Resp3
Source§type Error = RedisProtocolError
type Error = RedisProtocolError
The type of unrecoverable frame decoding errors. Read more
Source§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
Source§impl Encoder<BorrowedFrame<'_>> for Resp3
impl Encoder<BorrowedFrame<'_>> for Resp3
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more