{"id":22433573,"url":"https://github.com/gavinning/abtest","last_synced_at":"2025-03-27T07:45:39.467Z","repository":{"id":45004707,"uuid":"253163675","full_name":"gavinning/abtest","owner":"gavinning","description":"简单的流量分流ab实验模型","archived":false,"fork":false,"pushed_at":"2022-01-18T06:25:36.000Z","size":17,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T19:45:02.733Z","etag":null,"topics":["abtest"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavinning.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2020-04-05T05:38:42.000Z","updated_at":"2022-01-14T12:18:33.000Z","dependencies_parsed_at":"2022-08-30T07:30:59.463Z","dependency_job_id":null,"html_url":"https://github.com/gavinning/abtest","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fabtest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fabtest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fabtest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinning%2Fabtest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinning","download_url":"https://codeload.github.com/gavinning/abtest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806389,"owners_count":20675296,"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":["abtest"],"created_at":"2024-12-05T22:15:20.763Z","updated_at":"2025-03-27T07:45:39.448Z","avatar_url":"https://github.com/gavinning.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Abtest\n---\n流量均衡AB实验分组策略\n\n### Install\n```sh\nnpm i @4a/abtest\n```\n\n### Usage\n\n根据``abtestId``和``id``地址执行流量均衡分组\n```ts\n// abtest依赖redis\n// redis实例需支持promise，推荐配合ioredis使用\nimport ABTest from '@4a/abtest'\n\n// or\nconst ABTest = require('@4a/abtest').default.register(redis)\n\n// async函数内调用\nreturn await ABTest.grouping(testId, id) // Number\n\n// 设置redis过期时间，默认7d\n// 实验停止后，redis关联key 7天后过期\n// 实验期间每次命中实验都会刷新有效期\nreturn await ABTest.grouping(testId, id, 7 * 60 * 60)\n```\n\n### Notes\n```yaml\n# \n# 1、流量均衡分组\n# 2、默认分组结果 a:1, b:2, c:0\n# 3、根据id来进行固定分组\n# 4、可同时进行多个实验，按照abtestId区分\n# \n# 5、前端实验分组单步时长，过期时间前端可自行设置\n# \n# c:0 C组表示意外分组流量，其他分组失败的流量也会归到C组\n#\n```\n\nExample\n\u003e  \n\u003e npm test  \n\u003e  \n\u003e DEBUG=abtest npm test\n\u003e  ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fabtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinning%2Fabtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinning%2Fabtest/lists"}