Struct Conn

Source
pub struct Conn {
    pub context: Option<Box<dyn Any>>,
    /* private fields */
}
Expand description

A client connection.

Fields§

§context: Option<Box<dyn Any>>

A custom user-defined context.

Implementations§

Source§

impl Conn

Source

pub fn id(&self) -> u64

A distinct identifier for the connection.

Source

pub fn addr(&self) -> &SocketAddr

The connection socket address.

Source

pub fn next_command(&mut self) -> Option<Vec<Vec<u8>>>

Read the next command in the pipeline, if any.

This method is not typically needed, but it can be used for reading additional incoming commands that may be present. Which, may come in handy for specialized stuff like batching operations or for optimizing a locking strategy.

Source

pub fn write_string(&mut self, msg: &str)

Write a RESP Simple String to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-simple-strings

Source

pub fn write_null(&mut self)

Write a RESP Null Bulk String to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-bulk-strings

Source

pub fn write_error(&mut self, msg: &str)

Write a RESP Error to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-errors

Source

pub fn write_integer(&mut self, x: i64)

Write a RESP Integer to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-errors

Source

pub fn write_array(&mut self, count: usize)

Write a RESP Array to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-arrays

Source

pub fn write_bulk(&mut self, msg: &[u8])

Write a RESP Bulk String to client connection.

https://redis.io/docs/reference/protocol-spec/#resp-simple-strings

Source

pub fn write_raw(&mut self, raw: &[u8])

Write raw bytes to the client connection.

Source

pub fn close(&mut self)

Close the client connection.

Source

pub fn shutdown(&mut self)

Shutdown the server that was started by Server::serve.

This operation will gracefully shutdown the server by closing the all client connections, stopping the server listener, and waiting for the server resources to free.

Source

pub fn cross_close(&mut self, id: u64)

Close a client connection that is not this one.

The identifier is for a client connection that was connection to the same server as self. This operation can safely be called on the same identifier multiple time.

Auto Trait Implementations§

§

impl Freeze for Conn

§

impl !RefUnwindSafe for Conn

§

impl !Send for Conn

§

impl !Sync for Conn

§

impl Unpin for Conn

§

impl !UnwindSafe for Conn

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.