update
基于 HyperLogLog 实现的高性能 UV 统计系统,支持 TTL 过期,采用 gokv2 + redcon 作为 Redis 兼容存储。
visit-stat/ ├── main.go # Gin HTTP 服务入口 ├── kvserver.exe # Redis 兼容服务器 (gokv2 + redcon) ├── go.mod # Go 依赖 ├── README.md # 项目文档 ├── cmd/kvserver/ # KV 服务器 │ └── main.go ├── internal/ │ ├── cache/ │ │ ├── redis.go # Redis 接口定义 │ │ └── redis_client.go # go-redis 客户端实现 │ ├── handler/ │ │ └── handler.go # HTTP 接口 │ └── stat/ │ └── visit.go # 统计服务 └── frontend/ # 前端 (Vinext) ├── app/ ├── vite.config.ts └── package.json
./kvserver.exe
默认监听 localhost:6399
localhost:6399
./visit-stat.exe
服务默认在 http://localhost:8080 启动
http://localhost:8080
cd frontend pnpm install pnpm dev
前端默认在 http://localhost:5173 启动
http://localhost:5173
redis-cli -p 6399 # 测试 SET/GET 127.0.0.1:6399> SET mykey "hello" OK 127.0.0.1:6399> GET mykey "hello" # 测试 HyperLogLog 127.0.0.1:6399> PFADD uv:test "user1" (integer) 1 127.0.0.1:6399> PFADD uv:test "user2" (integer) 1 127.0.0.1:6399> PFCOUNT uv:test (integer) 2
internal/cache/redis.go 定义了 Redis 接口:
internal/cache/redis.go
type Redis interface { Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error Get(ctx context.Context, key string) (string, error) PFAdd(ctx context.Context, key string, elements ...string) error PFCount(ctx context.Context, keys ...string) (int64, error) // ... }
如需替换为真正 Redis,只需实现该接口即可。
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
Visit Stat - 访问统计系统
基于 HyperLogLog 实现的高性能 UV 统计系统,支持 TTL 过期,采用 gokv2 + redcon 作为 Redis 兼容存储。
技术栈
项目结构
功能特性
快速开始
1. 启动 KV 服务器 (Redis 兼容)
默认监听
localhost:63992. 启动 HTTP 后端
服务默认在
http://localhost:8080启动3. 启动前端
前端默认在
http://localhost:5173启动使用 redis-cli 测试
API 接口
设计说明
Redis 接口抽象
internal/cache/redis.go定义了 Redis 接口:如需替换为真正 Redis,只需实现该接口即可。
TTL 过期机制