All Projects → mattnenterprise → rust-hash-ring

mattnenterprise / rust-hash-ring

Licence: MIT license
A consistent hashing library in Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rust-hash-ring

hashring
Consistent-hashing: Hash ring implementation in Go
Stars: ✭ 30 (+0%)
Mutual labels:  consistent-hashing, consistent-hashing-library
Doramon
个人工具汇总:一致性哈希工具,Bitmap工具,布隆过滤器参数生成器,Yaml和properties互转工具,一键式生成整个前后端工具,单机高性能幂等工具,zookeeper客户端工具,分布式全局id生成器,时间转换工具,Http封装工具
Stars: ✭ 53 (+76.67%)
Mutual labels:  consistent-hashing
lua-resty-jump-consistent-hash
consistent hash for openresty
Stars: ✭ 24 (-20%)
Mutual labels:  consistent-hashing
hashring
Consistent hashing hashring implementation.
Stars: ✭ 28 (-6.67%)
Mutual labels:  consistent-hashing
consistent-hashing
an implementation of Consistent Hashing in pure Ruby using an AVL tree
Stars: ✭ 40 (+33.33%)
Mutual labels:  consistent-hashing
dynamic-sharding
用动态分片解决pushgateway高可用 单点 HA问题
Stars: ✭ 27 (-10%)
Mutual labels:  consistent-hashing
distributed-dev-learning
汇总、整理常用的分布式开发技术,给出demo,方便学习。包括数据分片、共识算法、一致性hash、分布式事务、非侵入的分布式链路追踪实现原理等内容。
Stars: ✭ 39 (+30%)
Mutual labels:  consistent-hashing

rust-hash-ring

Consistent Hashing library for Rust

Crates.io crates.io Crates.io CI Coverage Status

Documentation

Usage

extern crate hash_ring;

use hash_ring::HashRing;
use hash_ring::NodeInfo;

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!(
        "Key: '{}', Node: {}",
        "hello",
        hash_ring.get_node(("hello").to_string()).unwrap()
    );

    println!(
        "Key: '{}', Node: {}",
        "dude",
        hash_ring.get_node(("dude").to_string()).unwrap()
    );

    println!(
        "Key: '{}', Node: {}",
        "martian",
        hash_ring.get_node(("martian").to_string()).unwrap()
    );

    println!(
        "Key: '{}', Node: {}",
        "tardis",
        hash_ring.get_node(("tardis").to_string()).unwrap()
    );

    hash_ring.remove_node(&NodeInfo {
        host: "localhost",
        port: 15329,
    });

    println!(
        "Key: '{}', Node: {}",
        "hello",
        hash_ring.get_node(("hello").to_string()).unwrap()
    );

    hash_ring.add_node(&NodeInfo {
        host: "localhost",
        port: 15329,
    });

    println!(
        "Key: '{}', Node: {}",
        "hello",
        hash_ring.get_node(("hello").to_string()).unwrap()
    );
}

For an example of how to use a custom hash function you can look at examples/custom_hasher.rs

Contributing

Just fork it, implement your changes and submit a pull request.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].