consistent_hashing

Crates.ioconsistent_hashing
lib.rsconsistent_hashing
version0.5.0
sourcesrc
created_at2020-08-10 03:39:44.218182
updated_at2020-08-21 04:23:25.504828
descriptionConsistentHashing Alogrithm in Rust
homepage
repository
max_upload_size
id274902
size10,215
Stephen Leyva (srleyva)

documentation

README

Consistent Hash

Consistent Hashing is a distributed system algorithm for assigning values to partitions in a highly dynamic environment.

Example:

Using the algorithm to LB redis cache. (Crate redis = "0.17.0").

While the key must implement the hash trait to define a hashing strategy.

The Value must implement the Evict trait to define rebalancing behavior.

let mut ring: ConsistentHash<String,redis::Client> = match ConsistentHash::new(100).unwrap();

ring.add_node("redis://my-redis-node-1".to_string(), redis::Client::open("redis://my-redis-node-1")?).unwrap();
ring.add_node("redis://my-redis-node-2".to_string(), redis::Client::open("redis://my-redis-node-2")?).unwrap();
ring.add_node("redis://my-redis-node-3".to_string(), redis::Client::open("redis://my-redis-node-3")?).unwrap();
ring.add_node("redis://my-redis-node-4".to_string(), redis::Client::open("redis://my-redis-node-4")?).unwrap();

let client = match ring.get_node(String::from("some-key")){
    Some(node) => node,
    None => panic!("Not found!"),
};

let mut con = client.get_connection()?;
con.get("some-key");
Commit count: 0

cargo fmt