bikeshedder/deadpool

Redis Pool without configuration file

Closed this issue · 7 comments

Is there an example somewhere of creating a deadpool_redis pool manually (by hand) without using a configuration file-esque method?

Creating the structures by hand mostly works except for "connection" on deadpool_redis::Config. There also doesn't seem to be any example on how to use the builder without using it via a configuration into.

If you got a connection URL you can just call Config::from_url. There is an example right in the crate root: https://docs.rs/deadpool-redis/latest/deadpool_redis/index.html

use deadpool_redis::Config;

let cfg = Config::from_url("redis://127.0.0.1/");

If you want to use redis::ConnectionInfo struct instead of a URL you can create the Config object manually:

use deadpool_redis::Config;
use deadpool_redis::redis::{ConnectionAddr, ConnectionInfo, RedisConnectionInfo}

let cfg = Config {
    connection: ConnectionInfo {
        addr: ConnectionAddr::Tcp("localhost".into(), 6379),
        redis: RedisConnectionInfo {
            db: 0,
            username: None,
            password: None,
        },
    },
    ...Default::default(),
};

Maybe a Config::from_connection_info() method would make this more obvious?

Thanks @bikeshedder ! That would be helpful, I think. the scenario is to just manually make all of the attributes of the connection by hand, so a flattened struct would be dope.

I just found the real cause of your troubles. I forgot to export the ConnectionInfo and RedisConnectionInfo from the crate root.

The structs are marked as public but the config module is not. Normally this should give a linter error due to an non-public type used in a public interface.

I'll take care of this and release a new deadpool-redis version asap.

I thought perhaps I was going crazy... but those structures via config weren't marked public so it would be a type mismatch. Appreciate the extra look!

I just released deadpool-redis 0.11.1 which exports the missing types and also provides a Config::from_connection_info method.

TYSM!