添加redis/内存流控实现 #1

Merged
zhangdeman merged 6 commits from feature/init_version into master 2024-06-20 20:59:14 +08:00
3 changed files with 8 additions and 26 deletions
Showing only changes of commit 40bfaafa5a - Show all commits

2
go.mod
View File

@ -3,7 +3,7 @@ module git.zhangdeman.cn/zhangdeman/rate_limit
go 1.22.4
require (
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620103823-e8b63fb86391
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620104455-27e193a0ea47
github.com/go-redis/redis_rate/v10 v10.0.1
github.com/redis/go-redis/v9 v9.5.3
)

2
go.sum
View File

@ -12,6 +12,8 @@ git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620102217-f11c0a8216f6 h1:2q6yC/v
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620102217-f11c0a8216f6/go.mod h1:OImVgoNTw9qWxGrgrym0wtEMdx0ekaH7vJJKIgSpdEg=
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620103823-e8b63fb86391 h1:DLzEEPHoFPqQlowIU6VPT/45FVnmVG6lVoeI/VHZ+Ho=
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620103823-e8b63fb86391/go.mod h1:OImVgoNTw9qWxGrgrym0wtEMdx0ekaH7vJJKIgSpdEg=
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620104455-27e193a0ea47 h1:Taq1XyvDgFM/xTSEw3cUOWh4krgqfEDIzcVrqQ7Z3UE=
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620104455-27e193a0ea47/go.mod h1:OImVgoNTw9qWxGrgrym0wtEMdx0ekaH7vJJKIgSpdEg=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQcGqdzi4UdpZlp4f4FUPeBqoygP58pEKJkmN3ROsE0=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687/go.mod h1:gf7SW2TXATgux8pfdFedMkXWv2515OtIIM/5c4atkFw=
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=

View File

@ -19,35 +19,15 @@ import (
func TestRedis_AllowN(t *testing.T) {
_ = wrapRedis.Client.AddClient("test_rate_limit", &wrapRedisDefine.Options{
Addr: "127.0.0.1:6379",
Network: "TCP",
ClientName: "",
Protocol: 0,
Username: "",
Password: "123456",
MaxRetries: 0,
MinRetryBackoff: 0,
MaxRetryBackoff: 0,
DialTimeout: 0,
ReadTimeout: 0,
WriteTimeout: 0,
ContextTimeoutEnabled: false,
PoolFIFO: false,
PoolSize: 0,
PoolTimeout: 0,
MinIdleConn: 0,
MaxIdleConn: 0,
MaxActiveConn: 0,
ConnMaxIdleTime: 0,
ConnMaxLifetime: 0,
DisableIdentity: false,
IdentitySuffix: "",
Addr: "127.0.0.1:6379",
Password: "123456",
DB: 6,
})
RedisClient.SetRedisClient(wrapRedis.Client.GetRealClient("test_rate_limit"))
for i := 0; i < 100; i++ {
for i := 0; i < 1000; i++ {
allow, err := RedisClient.AllowN(context.Background(), &define.LimitConfig{
Key: "deman",
Total: 600,
Total: 60,
Rate: 10,
TimeInterval: 60,
}, 8)