Crate deadpool_redis_cluster

Source
👎Deprecated since 0.1.1: The functionality of redis_cluster_async has been merged into the redis crate rendering this crate obsolete. Please use deadpool-redis instead.
Expand description

§Deadpool for Redis Cluster Latest Version Unsafe forbidden Rust 1.63+

§⚠️ DEPRECATED! ⚠️

The functionality of redis_cluster_async has been merged into the redis crate rendering this crate obsolete.

Please use deadpool-redis instead.

§⚠️ DEPRECATED! ⚠️

Deadpool is a dead simple async pool for connections and objects of any type.

This crate implements a deadpool manager for redis-cluster.

§Features

FeatureDescriptionExtra dependenciesDefault
rt_tokio_1Enable support for tokio cratedeadpool/rt_tokio_1, redis/tokio-compyes
rt_async-std_1Enable support for async-std cratedeadpool/rt_async-std_1, redis/async-std-compno
serdeEnable support for serde cratedeadpool/serde, serde/deriveno

§Example

use std::env;
use deadpool_redis_cluster::{redis::{cmd, FromRedisValue}, Config, Runtime};

#[tokio::main]
async fn main() {
    let redis_urls = env::var("REDIS_CLUSTER__URLS")
        .unwrap()
        .split(',')
        .map(String::from)
        .collect::<Vec<_>>();
    let mut cfg = Config::from_urls(redis_urls);
    let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap();
    {
        let mut conn = pool.get().await.unwrap();
        cmd("SET")
            .arg(&["deadpool/test_key", "42"])
            .query_async::<_, ()>(&mut conn)
            .await.unwrap();
    }
    {
        let mut conn = pool.get().await.unwrap();
        let value: String = cmd("GET")
            .arg(&["deadpool/test_key"])
            .query_async(&mut conn)
            .await.unwrap();
        assert_eq!(value, "42".to_string());
    }
}

§Example with config and dotenv crate

use deadpool_redis_cluster::{redis::{cmd, FromRedisValue}, Runtime};
use dotenv::dotenv;

#[derive(Debug, serde::Deserialize)]
struct Config {
    #[serde(default)]
    redis_cluster: deadpool_redis_cluster::Config
}

impl Config {
      pub fn from_env() -> Result<Self, config::ConfigError> {
         config::Config::builder()
            .add_source(
                config::Environment::default()
                .separator("__")
                .try_parsing(true)
                .list_separator(","),
            )
            .build()?
            .try_deserialize()
    }
}

#[tokio::main]
async fn main() {
    dotenv().ok();
    let cfg = Config::from_env().unwrap();
    let pool = cfg.redis_cluster.create_pool(Some(Runtime::Tokio1)).unwrap();
    {
        let mut conn = pool.get().await.unwrap();
        cmd("SET")
            .arg(&["deadpool/test_key", "42"])
            .query_async::<_, ()>(&mut conn)
            .await.unwrap();
    }
    {
        let mut conn = pool.get().await.unwrap();
        let value: String = cmd("GET")
            .arg(&["deadpool/test_key"])
            .query_async(&mut conn)
            .await.unwrap();
        assert_eq!(value, "42".to_string());
    }
}

§FAQ

  • How can I enable features of the redis crate?

    Make sure that you depend on the same version of redis as deadpool-redis-cluster does and enable the needed features in your own Crate.toml file:

    [dependencies]
    deadpool-redis-cluster = { version = "0.9", features = ["serde"] }
    redis = { version = "0.21", default-features = false, features = ["tls"] }

§License

Licensed under either of

at your option.

Re-exports§

pub use redis;

Structs§

Client
This is a Redis cluster client.
ConfigDeprecated
Configuration object.
ConnectionDeprecated
Wrapper around redis_cluster_async::Connection.
ManagerDeprecated
Manager for creating and recycling redis_cluster_async connections.
Metrics
Statistics regarding an object returned by the pool
PoolConfig
Pool configuration.
RedisConnection
This is a connection of Redis cluster.
Status
The current pool status.
Timeouts
Timeouts when getting Objects from a Pool.

Enums§

ConfigErrorDeprecated
This error is returned if the configuration contains an error
Runtime
Enumeration for picking a runtime implementation.

Type Aliases§

BuildErrorDeprecated
Type alias for using deadpool::managed::BuildError with [redis_cluster].
CreatePoolErrorDeprecated
Type alias for using deadpool::managed::CreatePoolError with [redis_cluster].
HookDeprecated
Type alias for using deadpool::managed::Hook with [redis_cluster].
HookErrorDeprecated
Type alias for using deadpool::managed::HookError with [redis_cluster].
ObjectDeprecated
Type alias for using deadpool::managed::Object with [redis_cluster].
PoolDeprecated
Type alias for using deadpool::managed::Pool with [redis_cluster].
PoolBuilderDeprecated
Type alias for using deadpool::managed::PoolBuilder with [redis_cluster].
PoolErrorDeprecated
Type alias for using deadpool::managed::PoolError with [redis_cluster].