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

Add consistent hashing to the client #19

Closed
wants to merge 14 commits into from
Closed
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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "async-memcached"
version = "0.2.0"
authors = ["Toby Lawrence <[email protected]>"]
edition = "2018"
edition = "2021"
readme = "README.md"
license = "MIT"
description = "An Tokio-based memcached client for Rust."
Expand All @@ -18,14 +18,18 @@ dsn = "1.0"
btoi = "0.4"
pin-project = "1.0"
futures = "0.3"
tokio = { version = "1.26", default-features = false, features = ["io-util"] }
tokio = { version = "1.26", default-features = false, features = ["net", "io-util"] }
async-stream = "0.3"
url = "2.5.2"
crc32fast = "1.4.2"
blake3 = "1.5.1"
itertools = "0.13.0"

[dev-dependencies]
lazy_static = "1.4"
tokio = { version = "1.26", features = ["full"] }
rand = "0.8"
ctor = "0.2.8"

[features]
default = []
Expand Down
4 changes: 2 additions & 2 deletions examples/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_memcached::Client;

#[tokio::main]
async fn main() {
let mut client = Client::new("localhost:11211")
let mut client = Client::new(vec!["localhost:11211"])
.await
.expect("failed to create client");

Expand Down Expand Up @@ -30,7 +30,7 @@ async fn main() {
match client.stats().await {
Ok(stats) => {
println!("got {} stat entries!", stats.len());
println!("curr items: {:?}", stats.get("curr_items"));
println!("curr items: {:?}", stats[0].get("curr_items"));
}
Err(e) => println!("error while getting stats: {:?}", e),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use async_memcached::Client;

#[tokio::main]
async fn main() {
let mut client = Client::new("unix:///tmp/memcached.sock")
let mut client = Client::new(vec!["unix:///tmp/memcached.sock"])
.await
.expect("failed to create client");

Expand Down
57 changes: 57 additions & 0 deletions src/collectible_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::error::Error;

pub(crate) struct CollectibleResult<T> {
pub inner: Result<Vec<T>, Error>,
}

impl<T> Default for CollectibleResult<T> {
fn default() -> Self {
CollectibleResult {
inner: Ok(Vec::<T>::new()),
}
}
}

impl<T> Extend<Result<Vec<T>, Error>> for CollectibleResult<T> {
fn extend<I>(&mut self, iter: I)
where
I: IntoIterator<Item = Result<Vec<T>, Error>>,
{
if self.inner.is_err() {
return;
}

let result = self.inner.as_mut().unwrap();
for item in iter {
match item {
Ok(mut vec) => result.append(&mut vec),
Err(e) => {
self.inner = Err(e);
return;
}
}
}
}
}

impl<T> Extend<Result<T, Error>> for CollectibleResult<T> {
fn extend<I>(&mut self, iter: I)
where
I: IntoIterator<Item = Result<T, Error>>,
{
if self.inner.is_err() {
return;
}

let result = self.inner.as_mut().unwrap();
for item in iter {
match item {
Ok(val) => result.push(val),
Err(e) => {
self.inner = Err(e);
return;
}
}
}
}
}
Loading
Loading