Crates.io | nave |
lib.rs | nave |
version | 0.1.0 |
source | src |
created_at | 2020-09-03 10:22:52.460917 |
updated_at | 2020-09-03 10:22:52.460917 |
description | Thinking about the construction of distributed systems starting from the *consistent hash* algorithm. |
homepage | https://github.com/psiace/nave |
repository | https://github.com/psiace/nave |
max_upload_size | |
id | 284200 |
size | 20,860 |
Thinking about the construction of distributed systems starting from the consistent hash algorithm.
Nave's vision is to become the basis for building a robust and highly available distributed system. The possible final product is a collection of important algorithms or a framework in a certain sense.
You can already use it in projects, of course, currently only a port of rust-hash-ring.
HashRing
extern crate nave;
use nave::HashRing;
/// Custom Node Info.
#[derive(Clone, Debug)]
struct NodeInfo {
pub host: &'static str,
pub port: u16,
}
/// Impl ToString to format NodeInfo
impl ToString for NodeInfo {
fn to_string(&self) -> String {
format!("{}:{}", self.host, self.port)
}
}
fn main() {
let mut nodes: Vec<NodeInfo> = Vec::new();
nodes.push(NodeInfo { host: "localhost", port: 15324 });
nodes.push(NodeInfo { host: "localhost", port: 15325 });
nodes.push(NodeInfo { host: "localhost", port: 15326 });
nodes.push(NodeInfo { host: "localhost", port: 15327 });
nodes.push(NodeInfo { host: "localhost", port: 15328 });
nodes.push(NodeInfo { host: "localhost", port: 15329 });
let mut hash_ring: HashRing<NodeInfo> = HashRing::new(nodes, 10);
println!("{}", hash_ring.get_node(("hello").to_string()).unwrap().to_string());
println!("{}", hash_ring.get_node(("dude").to_string()).unwrap().to_string());
println!("{}", hash_ring.get_node(("martian").to_string()).unwrap().to_string());
println!("{}", hash_ring.get_node(("tardis").to_string()).unwrap().to_string());
hash_ring.remove_node(&NodeInfo { host: "localhost", port: 15329 });
println!("{}", hash_ring.get_node(("hello").to_string()).unwrap().to_string());
hash_ring.add_node(&NodeInfo { host: "localhost", port: 15329 });
println!("{}", hash_ring.get_node(("hello").to_string()).unwrap().to_string());
}
Chojan Shang - @PsiACE - psiace@outlook.com
Project Link: https://github.com/psiace/nave
If my work can make you feel happy, you can consider buying me a cup of coffee:
Licensed under either of
at your option.