{"id":13776517,"url":"https://github.com/ruoshan/lua-resty-jump-consistent-hash","last_synced_at":"2026-01-18T09:23:46.665Z","repository":{"id":70662407,"uuid":"54090168","full_name":"ruoshan/lua-resty-jump-consistent-hash","owner":"ruoshan","description":"consistent hash for openresty","archived":false,"fork":false,"pushed_at":"2019-01-15T06:48:04.000Z","size":24,"stargazers_count":25,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-02-14T11:49:58.926Z","etag":null,"topics":["consistent-hashing","luajit","openresty"],"latest_commit_sha":null,"homepage":"","language":"Perl","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/ruoshan.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}},"created_at":"2016-03-17T05:07:17.000Z","updated_at":"2022-07-28T05:32:20.000Z","dependencies_parsed_at":"2023-06-11T01:00:20.164Z","dependency_job_id":null,"html_url":"https://github.com/ruoshan/lua-resty-jump-consistent-hash","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruoshan%2Flua-resty-jump-consistent-hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruoshan%2Flua-resty-jump-consistent-hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruoshan%2Flua-resty-jump-consistent-hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruoshan%2Flua-resty-jump-consistent-hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruoshan","download_url":"https://codeload.github.com/ruoshan/lua-resty-jump-consistent-hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253551591,"owners_count":21926320,"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","luajit","openresty"],"created_at":"2024-08-03T18:00:28.059Z","updated_at":"2026-01-17T00:40:08.036Z","avatar_url":"https://github.com/ruoshan.png","language":"Perl","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"## Jump Consisten Hash for luajit\nA simple implementation of [this paper](http://arxiv.org/pdf/1406.2294.pdf).\n\n## Features\n- small memory footprint and fast\n- consistence is maintained through servers' updating\n\n## Installation\n```\nmake\nmake PREFIX=/usr/local/openresty install\n```\n\n## Usage\n\n* you can use the basic jchash module to do consistent-hash\n```\nlocal jchash = require \"resty.chash.jchash\"\n\nlocal buckets = 8\nlocal id = jchash.hash_short_str(\"random key\", buckets)\n```\n\n* or you can use the wrapping module `resty.chash.server` to consistent-hash a list of servers\n```\nlocal jchash_server = require \"resty.chash.server\"\n\nlocal my_servers = {\n    { \"127.0.0.1\", 80, 1},   -- {addr, port, weight} weight can be left out if it's 1\n    { \"127.0.0.2\", 80 },\n    { \"127.0.0.3\", 80 }\n}\n\nlocal cs, err = jchash_server.new(my_servers)\nlocal uri = ngx.var.uri\nlocal svr = cs:lookup(uri)\nlocal addr = svr[1]\nlocal port = svr[2]\n\n-- now you can use the ngx.balancer to do some consistent LB\n\n-- you can even update the servers list, and still maintain the consistence, eg.\nlocal my_new_servers = {\n    { \"127.0.0.2\", 80 },\n    { \"127.0.0.3\", 80 },\n    { \"127.0.0.4\", 80 }\n}\n\ncs:update_servers(my_new_servers)\nsvr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it stays the same,\n                       -- as we only update the 127.0.0.4.\n\n-- what's more, consistence is maintained even the number of servers changes! eg.\nlocal my_less_servers = {\n    { \"127.0.0.2\", 80 },\n    { \"127.0.0.3\", 80 }\n}\ncs:update_servers(my_less_servers)\nsvr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it stays the same,\n                       -- if the server was 127.0.0.4, then it has 50% chance to be\n                       -- 127.0.0.2 or 127.0.0.3\n\ncs:update_servers(my_new_servers)\nsvr = cs:lookup(uri)   -- if the server was 127.0.0.2, then it has 66% chance to stay the same\n\n```\n\n## Todo\n- ~~weight for the servers list~~ [done]\n- ~~Test::Nginx~~ [done]\n\n## Test\n\n```\nmake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruoshan%2Flua-resty-jump-consistent-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruoshan%2Flua-resty-jump-consistent-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruoshan%2Flua-resty-jump-consistent-hash/lists"}