[][src]Crate redis_cluster_async

This is a rust implementation for Redis cluster library.

This library extends redis-rs library to be able to use cluster. Client impletemts traits of ConnectionLike and Commands. So you can use redis-rs's access methods. If you want more information, read document of redis-rs.

Note that this library is currently not have features of Pubsub.

Example

use tokio::{prelude::*, runtime::current_thread::Runtime};

use redis_cluster_async::{Client, redis::{Commands, cmd}};

fn main() {
    let nodes = vec!["redis://127.0.0.1:7000/", "redis://127.0.0.1:7001/", "redis://127.0.0.1:7002/"];

    let mut runtime = Runtime::new().unwrap();
    runtime.block_on(future::lazy(|| {
        let client = Client::open(nodes).unwrap();
        client.get_connection().and_then(|connection| {
            cmd("SET").arg("test").arg("test_data").clone().query_async(connection)
                .and_then(|(connection, ())| {
                    cmd("GET").arg("test").clone().query_async(connection)
                })
                .map(|(_, res): (_, String)| {
                    assert_eq!(res, "test_data");
                })
        })
    })).unwrap()
}

Pipelining

use tokio::{prelude::*, runtime::current_thread::Runtime};

use redis_cluster_async::{Client, redis::{PipelineCommands, pipe}};

fn main() {
    let nodes = vec!["redis://127.0.0.1:7000/", "redis://127.0.0.1:7001/", "redis://127.0.0.1:7002/"];

    let mut runtime = Runtime::new().unwrap();
    runtime.block_on(future::lazy(|| {
        let client = Client::open(nodes).unwrap();
        client.get_connection().and_then(|connection| {
            let key = "test2";

            let mut pipe = pipe();
            pipe.rpush(key, "123").ignore()
                .ltrim(key, -10, -1).ignore()
                .expire(key, 60).ignore();
            pipe.query_async(connection)
                .map(|(_, ())| ())
        })
    })).unwrap();
}

Re-exports

pub use redis;

Structs

Client

This is a Redis cluster client.

Connection

This is a connection of Redis cluster.

Traits

Connect