{"id":13462107,"url":"https://github.com/pda/flexihash","last_synced_at":"2025-04-08T12:09:07.239Z","repository":{"id":53607807,"uuid":"130663","full_name":"pda/flexihash","owner":"pda","description":"Flexihash is a small PHP library which implements consistent hashing.","archived":false,"fork":false,"pushed_at":"2021-10-15T10:07:58.000Z","size":96,"stargazers_count":366,"open_issues_count":4,"forks_count":85,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-04-01T11:02:10.905Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","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/pda.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-02-17T07:40:23.000Z","updated_at":"2025-02-15T16:53:43.000Z","dependencies_parsed_at":"2022-09-19T04:32:32.078Z","dependency_job_id":null,"html_url":"https://github.com/pda/flexihash","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pda%2Fflexihash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pda%2Fflexihash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pda%2Fflexihash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pda%2Fflexihash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pda","download_url":"https://codeload.github.com/pda/flexihash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406082,"owners_count":20933803,"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":[],"created_at":"2024-07-31T12:00:38.802Z","updated_at":"2025-04-08T12:09:07.212Z","avatar_url":"https://github.com/pda.png","language":"PHP","funding_links":[],"categories":["Uncategorized","PHP","其他( Miscellaneous )"],"sub_categories":["Uncategorized"],"readme":"# Flexihash\n\n[![Build Status](https://travis-ci.org/pda/flexihash.svg?branch=master)](https://travis-ci.org/pda/flexihash) [![Coverage Status](https://coveralls.io/repos/github/pda/flexihash/badge.svg?branch=master)](https://coveralls.io/github/pda/flexihash?branch=master)\n\nFlexihash is a small PHP library which implements [consistent hashing](http://en.wikipedia.org/wiki/Consistent_hashing), which is most useful in distributed caching. It requires PHP5 and uses [PHPUnit](http://simpletest.org/) for unit testing.\n\n## Installation\n\n[Composer](https://getcomposer.org/) is the recommended installation technique. You can find flexihash on [Packagist](https://packagist.org/packages/flexihash/flexihash) so installation is as easy as\n```\ncomposer require flexihash/flexihash\n```\nor in your `composer.json`\n```json\n{\n    \"require\": {\n        \"flexihash/flexihash\": \"^3.0.0\"\n    }\n}\n```\n\n## Usage\n\n```php\n$hash = new Flexihash();\n\n// bulk add\n$hash-\u003eaddTargets(['cache-1', 'cache-2', 'cache-3']);\n\n// simple lookup\n$hash-\u003elookup('object-a'); // \"cache-1\"\n$hash-\u003elookup('object-b'); // \"cache-2\"\n\n// add and remove\n$hash\n  -\u003eaddTarget('cache-4')\n  -\u003eremoveTarget('cache-1');\n\n// lookup with next-best fallback (for redundant writes)\n$hash-\u003elookupList('object', 2); // [\"cache-2\", \"cache-4\"]\n\n// remove cache-2, expect object to hash to cache-4\n$hash-\u003eremoveTarget('cache-2');\n$hash-\u003elookup('object'); // \"cache-4\"\n```\n\n## Tests\n\n### Unit Test\n\n```\n% vendor/bin/phpunit\n```\n\n### Benchmark Test\n\n```\n% vendor/bin/phpunit tests/BenchmarkTest.php\n```\n\n## Further Reading\n\n  * http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/\n  * http://weblogs.java.net/blog/tomwhite/archive/2007/11/consistent_hash.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpda%2Fflexihash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpda%2Fflexihash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpda%2Fflexihash/lists"}