mirror of
https://github.com/rwf2/Rocket.git
synced 2025-02-26 02:22:18 +00:00
Add support for memcache connection pooling in 'rocket_contrib'.
This commit is contained in:
parent
a88bc95201
commit
5ce43ed4e9
@ -34,6 +34,7 @@ sqlite_pool = ["databases", "rusqlite", "r2d2_sqlite"]
|
|||||||
cypher_pool = ["databases", "rusted_cypher", "r2d2_cypher"]
|
cypher_pool = ["databases", "rusted_cypher", "r2d2_cypher"]
|
||||||
redis_pool = ["databases", "redis", "r2d2_redis"]
|
redis_pool = ["databases", "redis", "r2d2_redis"]
|
||||||
mongodb_pool = ["databases", "mongodb", "r2d2-mongodb"]
|
mongodb_pool = ["databases", "mongodb", "r2d2-mongodb"]
|
||||||
|
memcache_pool = ["databases", "memcache", "r2d2-memcache"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Global dependencies.
|
# Global dependencies.
|
||||||
@ -69,6 +70,8 @@ redis = { version = "0.9", optional = true }
|
|||||||
r2d2_redis = { version = "0.8", optional = true }
|
r2d2_redis = { version = "0.8", optional = true }
|
||||||
mongodb = { version = "0.3.12", optional = true }
|
mongodb = { version = "0.3.12", optional = true }
|
||||||
r2d2-mongodb = { version = "0.2.0", optional = true }
|
r2d2-mongodb = { version = "0.2.0", optional = true }
|
||||||
|
memcache = { version = "0.11", optional = true }
|
||||||
|
r2d2-memcache = { version = "0.3", optional = true }
|
||||||
|
|
||||||
# SpaceHelmet dependencies
|
# SpaceHelmet dependencies
|
||||||
time = { version = "0.1.40", optional = true }
|
time = { version = "0.1.40", optional = true }
|
||||||
|
@ -334,6 +334,7 @@
|
|||||||
//! | Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` |
|
//! | Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` |
|
||||||
//! | Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` |
|
//! | Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` |
|
||||||
//! | MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` |
|
//! | MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` |
|
||||||
|
//! | Memcache | [`memcache`] | [`memcache::Client`] | `memcache_pool` |
|
||||||
//!
|
//!
|
||||||
//! [Diesel]: https://diesel.rs
|
//! [Diesel]: https://diesel.rs
|
||||||
//! [`redis::Connection`]: https://docs.rs/redis/0.9.0/redis/struct.Connection.html
|
//! [`redis::Connection`]: https://docs.rs/redis/0.9.0/redis/struct.Connection.html
|
||||||
@ -352,6 +353,8 @@
|
|||||||
//! [`diesel::PgConnection`]: http://docs.diesel.rs/diesel/pg/struct.PgConnection.html
|
//! [`diesel::PgConnection`]: http://docs.diesel.rs/diesel/pg/struct.PgConnection.html
|
||||||
//! [`mongodb`]: https://github.com/mongodb-labs/mongo-rust-driver-prototype
|
//! [`mongodb`]: https://github.com/mongodb-labs/mongo-rust-driver-prototype
|
||||||
//! [`mongodb::db::Database`]: https://docs.rs/mongodb/0.3.12/mongodb/db/type.Database.html
|
//! [`mongodb::db::Database`]: https://docs.rs/mongodb/0.3.12/mongodb/db/type.Database.html
|
||||||
|
//! [`memcache`]: https://github.com/aisk/rust-memcache
|
||||||
|
//! [`memcache::Client`]: https://docs.rs/memcache/0.11.0/memcache/struct.Client.html
|
||||||
//!
|
//!
|
||||||
//! The above table lists all the supported database adapters in this library.
|
//! The above table lists all the supported database adapters in this library.
|
||||||
//! In order to use particular `Poolable` type that's included in this library,
|
//! In order to use particular `Poolable` type that's included in this library,
|
||||||
@ -405,6 +408,9 @@ use self::r2d2::ManageConnection;
|
|||||||
#[cfg(feature = "mongodb_pool")] pub extern crate mongodb;
|
#[cfg(feature = "mongodb_pool")] pub extern crate mongodb;
|
||||||
#[cfg(feature = "mongodb_pool")] pub extern crate r2d2_mongodb;
|
#[cfg(feature = "mongodb_pool")] pub extern crate r2d2_mongodb;
|
||||||
|
|
||||||
|
#[cfg(feature = "memcache_pool")] pub extern crate memcache;
|
||||||
|
#[cfg(feature = "memcache_pool")] pub extern crate r2d2_memcache;
|
||||||
|
|
||||||
/// A structure representing a particular database configuration.
|
/// A structure representing a particular database configuration.
|
||||||
///
|
///
|
||||||
/// For the following configuration:
|
/// For the following configuration:
|
||||||
@ -798,6 +804,17 @@ impl Poolable for mongodb::db::Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "memcache_pool")]
|
||||||
|
impl Poolable for memcache::Client {
|
||||||
|
type Manager = r2d2_memcache::MemcacheConnectionManager;
|
||||||
|
type Error = DbError<memcache::MemcacheError>;
|
||||||
|
|
||||||
|
fn pool(config: DatabaseConfig) -> Result<r2d2::Pool<Self::Manager>, Self::Error> {
|
||||||
|
let manager = r2d2_memcache::MemcacheConnectionManager::new(config.url);
|
||||||
|
r2d2::Pool::builder().max_size(config.pool_size).build(manager).map_err(DbError::PoolError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
@ -96,6 +96,7 @@ if [ "$1" = "--contrib" ]; then
|
|||||||
cypher_pool
|
cypher_pool
|
||||||
redis_pool
|
redis_pool
|
||||||
mongodb_pool
|
mongodb_pool
|
||||||
|
memcache_pool
|
||||||
)
|
)
|
||||||
|
|
||||||
pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1
|
pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1
|
||||||
|
@ -188,6 +188,7 @@ Presently, Rocket provides built-in support for the following databases:
|
|||||||
| Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` |
|
| Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` |
|
||||||
| Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` |
|
| Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` |
|
||||||
| MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` |
|
| MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` |
|
||||||
|
| Memcache | [`memcache`] | [`memcache::Client`] | `memcache_pool` |
|
||||||
|
|
||||||
[`r2d2`]: https://crates.io/crates/r2d2
|
[`r2d2`]: https://crates.io/crates/r2d2
|
||||||
[Diesel]: https://diesel.rs
|
[Diesel]: https://diesel.rs
|
||||||
@ -207,6 +208,8 @@ Presently, Rocket provides built-in support for the following databases:
|
|||||||
[`diesel::PgConnection`]: http://docs.diesel.rs/diesel/pg/struct.PgConnection.html
|
[`diesel::PgConnection`]: http://docs.diesel.rs/diesel/pg/struct.PgConnection.html
|
||||||
[`mongodb`]: https://github.com/mongodb-labs/mongo-rust-driver-prototype
|
[`mongodb`]: https://github.com/mongodb-labs/mongo-rust-driver-prototype
|
||||||
[`mongodb::db::Database`]: https://docs.rs/mongodb/0.3.12/mongodb/db/type.Database.html
|
[`mongodb::db::Database`]: https://docs.rs/mongodb/0.3.12/mongodb/db/type.Database.html
|
||||||
|
[`memcache`]: https://github.com/aisk/rust-memcache
|
||||||
|
[`memcache::Client`]: https://docs.rs/memcache/0.11.0/memcache/struct.Client.html
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user