{"id":13700937,"url":"https://github.com/lafikl/consistent","last_synced_at":"2025-05-16T13:07:20.742Z","repository":{"id":21765492,"uuid":"93978334","full_name":"lafikl/consistent","owner":"lafikl","description":"A Go library that implements Consistent Hashing and Consistent Hashing With Bounded Loads.","archived":false,"fork":false,"pushed_at":"2023-12-06T16:22:47.000Z","size":82,"stargazers_count":683,"open_issues_count":4,"forks_count":49,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-09T08:06:43.163Z","etag":null,"topics":["consistent-hashing","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lafikl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-11T03:04:00.000Z","updated_at":"2025-02-28T03:02:12.000Z","dependencies_parsed_at":"2024-06-18T13:42:47.186Z","dependency_job_id":null,"html_url":"https://github.com/lafikl/consistent","commit_stats":{"total_commits":19,"total_committers":7,"mean_commits":"2.7142857142857144","dds":0.3157894736842105,"last_synced_commit":"bdd3606bfc3e6134848986a8d1709b469558b56f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lafikl%2Fconsistent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lafikl%2Fconsistent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lafikl%2Fconsistent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lafikl%2Fconsistent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lafikl","download_url":"https://codeload.github.com/lafikl/consistent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535829,"owners_count":22087399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consistent-hashing","golang"],"created_at":"2024-08-02T20:01:09.608Z","updated_at":"2025-05-16T13:07:20.722Z","avatar_url":"https://github.com/lafikl.png","language":"Go","readme":"# Package consistent\nA Golang implementation of Consistent Hashing and Consistent Hashing With Bounded Loads.\n\nhttps://en.wikipedia.org/wiki/Consistent_hashing\n\nhttps://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html\n\n\n### Consistent Hashing Example\n\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"github.com/lafikl/consistent\"\n)\n\nfunc main() {\n\tc := consistent.New()\n\n\t// adds the hosts to the ring\n\tc.Add(\"127.0.0.1:8000\")\n\tc.Add(\"92.0.0.1:8000\")\n\n\t// Returns the host that owns `key`.\n\t//\n\t// As described in https://en.wikipedia.org/wiki/Consistent_hashing\n\t//\n\t// It returns ErrNoHosts if the ring has no hosts in it.\n\thost, err := c.Get(\"/app.html\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Println(host)\n}\n\n```\n\n\n### Consistent Hashing With Bounded Loads Example\n\n```go\n\npackage main\n\nimport (\n\t\"log\"\n\t\"github.com/lafikl/consistent\"\n)\n\nfunc main() {\n\tc := consistent.New()\n\n\t// adds the hosts to the ring\n\tc.Add(\"127.0.0.1:8000\")\n\tc.Add(\"92.0.0.1:8000\")\n\n\t// It uses Consistent Hashing With Bounded loads\n\t// https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html\n\t// to pick the least loaded host that can serve the key\n\t//\n\t// It returns ErrNoHosts if the ring has no hosts in it.\n\t//\n\thost, err := c.GetLeast(\"/app.html\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// increases the load of `host`, we have to call it before sending the request\n\tc.Inc(host)\n\n\t// send request or do whatever\n\tlog.Println(\"send request to\", host)\n\n\t// call it when the work is done, to update the load of `host`.\n\tc.Done(host)\n\n}\n\n```\n\n\n## Docs\n\nhttps://godoc.org/github.com/lafikl/consistent\n\n\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2017 Khalid Lafi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flafikl%2Fconsistent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flafikl%2Fconsistent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flafikl%2Fconsistent/lists"}