Skip to main content

Request

Struct Request 

Source
pub struct Request<'a> { /* private fields */ }
Expand description

A request builder for encoding Redis commands.

This provides a fluent interface for building and encoding commands.

§Example

use resp_proto::Request;

let mut buf = vec![0u8; 1024];

// Simple GET
let len = Request::get(b"mykey").encode(&mut buf);

// SET with expiration
let len = Request::set(b"mykey", b"myvalue").ex(3600).encode(&mut buf);

Implementations§

Source§

impl<'a> Request<'a>

Source

pub fn new(args: Vec<&'a [u8]>) -> Self

Create a new request with the given arguments.

Source

pub fn ping() -> Self

Create a PING command.

Source

pub fn get(key: &'a [u8]) -> Self

Create a GET command.

Source

pub fn set(key: &'a [u8], value: &'a [u8]) -> SetRequest<'a>

Create a SET command.

Source

pub fn del(key: &'a [u8]) -> Self

Create a DEL command.

Source

pub fn mget(keys: &[&'a [u8]]) -> Self

Create a MGET command (multiple keys).

Source

pub fn config_get(key: &'a [u8]) -> Self

Create a CONFIG GET command.

Source

pub fn config_set(key: &'a [u8], value: &'a [u8]) -> Self

Create a CONFIG SET command.

Source

pub fn flushdb() -> Self

Create a FLUSHDB command.

Source

pub fn flushall() -> Self

Create a FLUSHALL command.

Source

pub fn cluster_slots() -> Self

Create a CLUSTER SLOTS command.

Source

pub fn cluster_nodes() -> Self

Create a CLUSTER NODES command.

Source

pub fn cluster_info() -> Self

Create a CLUSTER INFO command.

Source

pub fn cluster_myid() -> Self

Create a CLUSTER MYID command.

Source

pub fn asking() -> Self

Create an ASKING command.

Source

pub fn readonly() -> Self

Create a READONLY command.

Source

pub fn readwrite() -> Self

Create a READWRITE command.

Source

pub fn cmd(name: &'a [u8]) -> Self

Create a custom command with arbitrary arguments.

Source

pub fn arg(self, arg: &'a [u8]) -> Self

Add an argument to the command.

Source

pub fn encode(&self, buf: &mut [u8]) -> usize

Encode this request into a buffer.

Returns the number of bytes written.

§Panics

Panics if the buffer is too small.

Source

pub fn encoded_len(&self) -> usize

Calculate the encoded length of this request.

Trait Implementations§

Source§

impl<'a> Clone for Request<'a>

Source§

fn clone(&self) -> Request<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Request<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Request<'a>

§

impl<'a> RefUnwindSafe for Request<'a>

§

impl<'a> Send for Request<'a>

§

impl<'a> Sync for Request<'a>

§

impl<'a> Unpin for Request<'a>

§

impl<'a> UnsafeUnpin for Request<'a>

§

impl<'a> UnwindSafe for Request<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.