{"id":18623952,"url":"https://github.com/lloydzhou/redisab","last_synced_at":"2026-04-19T03:06:15.368Z","repository":{"id":70347330,"uuid":"304031168","full_name":"lloydzhou/redisab","owner":"lloydzhou","description":"abtest based on redis and openresty","archived":false,"fork":false,"pushed_at":"2024-06-13T05:18:12.000Z","size":4,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-01T14:51:57.028Z","etag":null,"topics":["abtest","openresty","redis"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/lloydzhou.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-14T13:53:58.000Z","updated_at":"2024-10-10T09:43:05.000Z","dependencies_parsed_at":"2024-11-07T04:39:18.503Z","dependency_job_id":null,"html_url":"https://github.com/lloydzhou/redisab","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lloydzhou/redisab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lloydzhou%2Fredisab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lloydzhou%2Fredisab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lloydzhou%2Fredisab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lloydzhou%2Fredisab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lloydzhou","download_url":"https://codeload.github.com/lloydzhou/redisab/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lloydzhou%2Fredisab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31992822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","openresty","redis"],"created_at":"2024-11-07T04:26:49.346Z","updated_at":"2026-04-19T03:06:15.349Z","avatar_url":"https://github.com/lloydzhou.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RedisAB\n\n## 总体设计\n1. 数据持久化到redis里面\n2. 大量使用redis-lua脚本（基本每一个接口都是使用redis-lua脚本实现，提升性能的同时，能利用redis-lua脚本的原子性达到类似事务的效果）\n3. 设计一个测试环境和正式环境，通过\"X-Env\"识别，数据通过redis db分开存储\n4. 通过\"X-User-Id\"传递user_id\n5. 设计一个控制台管理流量层和实验（登录使用http auth_basic）\n\n### murmurhash2\n```\n  local ffi = require \"ffi\"\n  ffi.cdef[[\n    typedef unsigned char u_char;\n    uint32_t ngx_murmur_hash2(u_char *data, size_t len);\n  ]]\n  murmurhash2 = function(value)\n    return tonumber(ffi.C.ngx_murmur_hash2(ffi.cast('uint8_t *', value), #value))\n  end\n```\n\n\n## 启动项目\n```\ndocker pull lloydzhou/ab\n\ndocker run --rm -it -e INTERVAL=60 -e HTPASSWD='abadmin:$apr1$EJ2gyYP1$JirougEJ3sK/nF8aj63Zw1' -v `pwd`/data:/data:rw -p 8011:80 lloydzhou/ab\n\ndocker run --rm -it -e INTERVAL=60 -e HTPASSWD=\"$(docker run --rm -it xmartlabs/htpasswd abadmin abpasswd )\" -v `pwd`/data:/data/:rw -p 8011:80  lloydzhou/ab\n\n```\n###  params\n`INTERVAL`:   interval for run crontab to calc data  \n`HTPASSWD`:  http base auth for login to admin panel, default is `abadmin/abpasswd`\n\n\n## 接口\n1. 获取变量接口\n```\ncurl \"localhost:8011/ab/var?name=var1\" -H 'X-Env: dev' -H 'X-User-Id: 0001'\n\n--\u003e \n\n返回当前user_id(0001)在这个实验中分配的变量: 类型是数字，值为2\n{\"value\":\"2\",\"msg\":\"success\",\"layer\":\"layer1\",\"code\":0,\"hash\":838060847,\"test\":\"test1\",\"type\":\"number\"}\n```\n2. 回传指标接口\n\n```\n上传名字为target1的指标，代表user_id=0001这个用户在当前实验版本下产生转化的指标\ncurl \"localhost:8011/ab/track?name=var1\" -H 'X-Env: dev' -H 'X-User-Id: 0001' -d '{\"target1\": 1}'\n\n--\u003e \n\n{\"msg\":\"success\",\"code\":0}\n```\n\n## demo\n1. 创建一个名字叫layer1的流量层\n![image](https://user-images.githubusercontent.com/1826685/96210922-92180400-0fa5-11eb-9b35-6d818ec3f820.png)\n2. 在这个流量曾创建一个名字叫test1的实验\n3. 给这个实验创建两个版本(value=0/1)分别分配50%的流量\n4. 给这个实验创建一个叫做target1的指标\n![image](https://user-images.githubusercontent.com/1826685/96210953-a2c87a00-0fa5-11eb-988e-de6645b9c852.png)\n![image](https://user-images.githubusercontent.com/1826685/96210985-b542b380-0fa5-11eb-8183-6118a49cd3ba.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flloydzhou%2Fredisab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flloydzhou%2Fredisab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flloydzhou%2Fredisab/lists"}