Crates.io | flexihash |
lib.rs | flexihash |
version | 0.1.8 |
source | src |
created_at | 2020-03-29 12:16:18.718426 |
updated_at | 2024-03-15 18:34:56.145277 |
description | Consistent hashing following the API and compatible with flexihash-php and flexihash-py |
homepage | https://shish.io |
repository | https://github.com/shish/flexihash-rs/ |
max_upload_size | |
id | 224040 |
size | 22,278 |
A rust port of https://github.com/pda/flexihash , aiming for 1:1 compatibility
use flexihash::Flexihash;
let fh = Flexihash::new();
// bulk add
fh.add_targets(vec!["cache-1", "cache-2", "cache-3"]);
// simple lookup
fh.lookup("object-a"); // "cache-1"
fh.lookup("object-b"); // "cache-2"
// add and remove
fh.add_target("cache-4");
fh.remove_target("cache-1");
// lookup with next-best fallback (for redundant writes)
fh.lookup_list("object", 2) // ["cache-2", "cache-4"]
// remove cache-2, expect object to hash to cache-4
fh.remove_target("cache-2")
fh.lookup("object") // "cache-4"