Crate r2d2_redis_cluster[][src]

Redis cluster support for the r2d2 connection pool.

Example

extern crate r2d2;
extern crate r2d2_redis_cluster;

use std::thread;

use r2d2::Pool;
use r2d2_redis_cluster::{Commands, RedisClusterConnectionManager};

fn main() {
    let redis_uri = vec!["redis://127.0.0.1:6379", "redis://127.0.0.1:6378", "redis://127.0.0.1:6377"];
    let manager = RedisClusterConnectionManager::new(redis_uri).unwrap();
    let pool = Pool::builder()
        .build(manager)
        .unwrap();

    let mut handles = Vec::new();

    for _ in 0..10 {
        let pool = pool.clone();
        handles.push(thread::spawn(move || {
            let connection = pool.get().unwrap();
            let _: u64 = connection.incr("test", 1).unwrap();
        }));
    }

    for h in handles {
        h.join().unwrap();
    }

    let connection = pool.get().unwrap();
    let res: u64 = connection.get("test").unwrap();

    assert_eq!(res, 10);
}

Structs

RedisClusterConnectionManager

An r2d2::ConnectionManager for redis_cluster_rs::Client.

Traits

Commands

Implements common redis commands for connection like objects. This allows you to send commands straight to a connection or client. It is also implemented for redis results of clients which makes for very convenient access in some basic cases.

ConnectionLike

Implements the "stateless" part of the connection interface that is used by the different objects in redis-rs. Primarily it obviously applies to Connection object but also some other objects implement the interface (for instance whole clients or certain redis results).

Type Definitions

RedisResult

Library generic result type.