Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadpool-memcached #368

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ services:
- rabbitmq.env
volumes:
- rabbitmq-data:/var/lib/rabbitmq

memcached:
image: memcached:1.6
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ jobs:
# Disable Diesel MSRV check as it keeps failing for no obvious reason.
#- { crate: deadpool-diesel, msrv: '1.78.0' }
- { crate: deadpool-lapin, msrv: '1.75.0' }
- { crate: deadpool-memcached, msrv: '1.75.0' }
- { crate: deadpool-postgres, msrv: '1.75.0' }
- { crate: deadpool-redis, msrv: '1.75.0' }
- { crate: deadpool-sqlite, msrv: '1.77.0' }
Expand Down Expand Up @@ -191,6 +192,7 @@ jobs:
- deadpool
- deadpool-diesel
- deadpool-lapin
- deadpool-memcached
- deadpool-postgres
- deadpool-redis
- deadpool-sqlite
Expand Down Expand Up @@ -232,6 +234,10 @@ jobs:
RABBITMQ_DEFAULT_USER: deadpool
RABBITMQ_DEFAULT_PASS: deadpool
RABBITMQ_DEFAULT_VHOST: deadpool
memcached:
image: memcached:1.6
ports:
- 11211:11211
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand All @@ -252,8 +258,7 @@ jobs:
REDIS_SENTINEL__MASTER_NAME: "mymaster"
REDIS_CLUSTER__URLS: redis://127.0.0.1:7000,redis://127.0.0.1:7001
AMQP__URL: amqp://deadpool:[email protected]/deadpool


MEMCACHED__ADDR: 127.0.0.1:11211


############
Expand All @@ -270,6 +275,7 @@ jobs:
- deadpool
- deadpool-diesel
- deadpool-lapin
- deadpool-memcached
- deadpool-postgres
- deadpool-redis
- deadpool-sqlite
Expand Down
4 changes: 3 additions & 1 deletion memcached/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Update `async-memcached` to version `0.4`

## [0.3.2] - 2024-05-04

- Update `deadpool` dependency to version `0.12`
Expand Down Expand Up @@ -44,4 +46,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.3.0]: https://github.com/bikeshedder/deadpool/compare/deadpool-memcached-v0.2.0...deadpool-memcached-v0.3.0
[0.2.0]: https://github.com/bikeshedder/deadpool/compare/deadpool-memcached-v0.1.2...deadpool-memcached-v0.2.0
[0.1.2]: https://github.com/bikeshedder/deadpool/compare/deadpool-memcached-v0.1.0...deadpool-memcached-v0.1.2
[0.1.0]: https://github.com/bikeshedder/deadpool/deadpool-memcached-v0.1.0
[0.1.0]: https://github.com/bikeshedder/deadpool/deadpool-memcached-v0.1.0
5 changes: 4 additions & 1 deletion memcached/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["tcp"]
tcp = ["async-memcached/tcp"]

[dependencies]
async-memcached = { version = "0.1", default-features = false }
async-memcached = { version = "0.4", default-features = false }
deadpool = { path = "../", version = "0.12.0", default-features = false, features = [
"managed",
] }
Expand All @@ -32,5 +32,8 @@ deadpool = { path = "../", version = "0.12.0", default-features = false, feature
# again.
tokio = { version = "1.0", default-features = false, features = ["net"] }

[dev-dependencies]
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[package.metadata.cargo-machete]
ignored = ["tokio"]
12 changes: 9 additions & 3 deletions memcached/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ type RecycleResult = deadpool::managed::RecycleResult<Error>;
type ConfigError = Infallible;

pub use deadpool::managed::reexports::*;
deadpool::managed_reexports!("memcached", Manager, Client, Error, ConfigError);
deadpool::managed_reexports!(
"memcached",
Manager,
deadpool::managed::Object<Manager>,
Error,
ConfigError
);

/// The manager for creating and recyling memcache connections
pub struct Manager {
Expand All @@ -26,8 +32,8 @@ pub struct Manager {

impl Manager {
/// Create a new manager for the given address.
pub fn new(addr: String) -> Self {
Self { addr }
pub fn new(addr: impl Into<String>) -> Self {
Self { addr: addr.into() }
}
}

Expand Down
24 changes: 24 additions & 0 deletions memcached/tests/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Basic tests for deadpool-memcached

use std::env;

use deadpool_memcached::{Manager, Pool};

fn create_pool() -> Pool {
let addr = env::var("MEMCACHED__ADDR").unwrap();
let manager = Manager::new(addr);
Pool::builder(manager).build().unwrap()
}

#[tokio::test]
async fn test_set_get() {
let test_key = "test:basic:test_set_get";
let test_value = "answer_42";
let pool = create_pool();
let mut conn = pool.get().await.unwrap();
let _ = conn.delete(test_key).await;
assert_eq!(conn.get(test_key).await.unwrap(), None);
conn.set(test_key, test_value, None, None).await.unwrap();
let value = String::from_utf8(conn.get(test_key).await.unwrap().unwrap().data).unwrap();
assert_eq!(value, test_value);
}
Loading