Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 5ce43ed4e97261272bbe7d506c534750db71aa32
parent a88bc9520186c60525bf4196a38d7a9a00cca5b2
Author: An Long <aisk1988@gmail.com>
Date:   Sat,  5 Jan 2019 00:19:09 +0800

Add support for memcache connection pooling in 'rocket_contrib'.

Diffstat:
Mcontrib/lib/Cargo.toml | 3+++
Mcontrib/lib/src/databases.rs | 17+++++++++++++++++
Mscripts/test.sh | 1+
Msite/guide/6-state.md | 3+++
4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/contrib/lib/Cargo.toml b/contrib/lib/Cargo.toml @@ -34,6 +34,7 @@ sqlite_pool = ["databases", "rusqlite", "r2d2_sqlite"] cypher_pool = ["databases", "rusted_cypher", "r2d2_cypher"] redis_pool = ["databases", "redis", "r2d2_redis"] mongodb_pool = ["databases", "mongodb", "r2d2-mongodb"] +memcache_pool = ["databases", "memcache", "r2d2-memcache"] [dependencies] # Global dependencies. @@ -69,6 +70,8 @@ redis = { version = "0.9", optional = true } r2d2_redis = { version = "0.8", optional = true } mongodb = { version = "0.3.12", 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 time = { version = "0.1.40", optional = true } diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs @@ -334,6 +334,7 @@ //! | Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` | //! | Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` | //! | MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` | +//! | Memcache | [`memcache`] | [`memcache::Client`] | `memcache_pool` | //! //! [Diesel]: https://diesel.rs //! [`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 //! [`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 +//! [`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. //! 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 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. /// /// 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)] mod tests { use std::collections::BTreeMap; diff --git a/scripts/test.sh b/scripts/test.sh @@ -96,6 +96,7 @@ if [ "$1" = "--contrib" ]; then cypher_pool redis_pool mongodb_pool + memcache_pool ) pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1 diff --git a/site/guide/6-state.md b/site/guide/6-state.md @@ -188,6 +188,7 @@ Presently, Rocket provides built-in support for the following databases: | Neo4j | [`rusted_cypher`] | [`rusted_cypher::GraphClient`] | `cypher_pool` | | Redis | [`redis-rs`] | [`redis::Connection`] | `redis_pool` | | MongoDB | [`mongodb`] | [`mongodb::db::Database`] | `mongodb_pool` | +| Memcache | [`memcache`] | [`memcache::Client`] | `memcache_pool` | [`r2d2`]: https://crates.io/crates/r2d2 [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 [`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 +[`memcache`]: https://github.com/aisk/rust-memcache +[`memcache::Client`]: https://docs.rs/memcache/0.11.0/memcache/struct.Client.html ### Usage