Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

The client type.

Implementations§

Source§

impl Client

The client acts as connector to the redis server. By itself it does not do much other than providing a convenient way to fetch a connection from it. In the future the plan is to provide a connection pool in the client.

When opening a client a URL in the following format should be used:

redis://host:port/db

Example usage::

let client = td_rredis::Client::open("redis://127.0.0.1/").unwrap();
let con = client.get_connection().unwrap();
Source

pub fn open(info: &str) -> RedisResult<Client>

Connects to a redis server and returns a client. This does not actually open a connection yet but it does perform some basic checks on the URL that might make the operation fail.

Examples found in repository?
examples/redis.rs (line 14)
13fn test_get() -> redis::RedisResult<()> {
14    let client = redis::Client::open("redis://127.0.0.1/").unwrap();
15    let con = client.get_connection().unwrap();
16
17    redis::cmd("DEL").arg("foo").execute(&con);
18    for x in 0..600 {
19        redis::cmd("SADD").arg("foo").arg(x).execute(&con);
20    }
21    Ok(())
22}
Source

pub fn get_connection(&self) -> RedisResult<Connection>

Instructs the client to actually connect to redis and returns a connection object. The connection object can be used to send commands to the server. This can fail with a variety of errors (like unreachable host) so it’s important that you handle those errors.

Examples found in repository?
examples/redis.rs (line 15)
13fn test_get() -> redis::RedisResult<()> {
14    let client = redis::Client::open("redis://127.0.0.1/").unwrap();
15    let con = client.get_connection().unwrap();
16
17    redis::cmd("DEL").arg("foo").execute(&con);
18    for x in 0..600 {
19        redis::cmd("SADD").arg("foo").arg(x).execute(&con);
20    }
21    Ok(())
22}
Source

pub fn get_pubsub(&self) -> RedisResult<PubSub>

Returns a PubSub connection. A pubsub connection can be used to listen to messages coming in through the redis publish/subscribe system.

Note that redis’ pubsub operates across all databases.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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.