pub struct Resp2 { /* private fields */ }
Available on crate features
codec
and resp2
only.Expand description
A framed RESP2 codec.
use futures::{SinkExt, StreamExt};
use redis_protocol::{
codec::{resp2_encode_command, Resp2},
resp2::types::{BytesFrame, Resp2Frame},
};
use tokio::net::TcpStream;
use tokio_util::codec::Framed;
async fn example() {
let socket = TcpStream::connect("127.0.0.1:6379").await.unwrap();
let mut framed = Framed::new(socket, Resp2::default());
let auth = resp2_encode_command("AUTH foo bar");
let get_foo = resp2_encode_command("GET foo");
let _ = framed.send(auth).await.unwrap();
let response = framed.next().await.unwrap().unwrap();
assert_eq!(response.as_str().unwrap(), "OK");
let _ = framed.send(get_foo).await.unwrap();
let response = framed.next().await.unwrap().unwrap();
assert_eq!(response, BytesFrame::Null);
}
Implementations§
Trait Implementations§
Source§impl Decoder for Resp2
impl Decoder for Resp2
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 Resp2
impl Encoder<BorrowedFrame<'_>> for Resp2
Auto Trait Implementations§
impl Freeze for Resp2
impl RefUnwindSafe for Resp2
impl Send for Resp2
impl Sync for Resp2
impl Unpin for Resp2
impl UnwindSafe for Resp2
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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