调试完成redis流控
This commit is contained in:
parent
545523e324
commit
40bfaafa5a
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.zhangdeman.cn/zhangdeman/rate_limit
|
|||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|
||||||
require (
|
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/go-redis/redis_rate/v10 v10.0.1
|
||||||
github.com/redis/go-redis/v9 v9.5.3
|
github.com/redis/go-redis/v9 v9.5.3
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -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-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 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-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 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-20240325080031-1f58204e8687/go.mod h1:gf7SW2TXATgux8pfdFedMkXWv2515OtIIM/5c4atkFw=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd h1:2Y37waOVCmVvx0Rp8VGEptE2/2JVMImtxB4dKKDk/3w=
|
||||||
|
@ -19,35 +19,15 @@ import (
|
|||||||
|
|
||||||
func TestRedis_AllowN(t *testing.T) {
|
func TestRedis_AllowN(t *testing.T) {
|
||||||
_ = wrapRedis.Client.AddClient("test_rate_limit", &wrapRedisDefine.Options{
|
_ = wrapRedis.Client.AddClient("test_rate_limit", &wrapRedisDefine.Options{
|
||||||
Addr: "127.0.0.1:6379",
|
Addr: "127.0.0.1:6379",
|
||||||
Network: "TCP",
|
Password: "123456",
|
||||||
ClientName: "",
|
DB: 6,
|
||||||
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: "",
|
|
||||||
})
|
})
|
||||||
RedisClient.SetRedisClient(wrapRedis.Client.GetRealClient("test_rate_limit"))
|
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{
|
allow, err := RedisClient.AllowN(context.Background(), &define.LimitConfig{
|
||||||
Key: "deman",
|
Key: "deman",
|
||||||
Total: 600,
|
Total: 60,
|
||||||
Rate: 10,
|
Rate: 10,
|
||||||
TimeInterval: 60,
|
TimeInterval: 60,
|
||||||
}, 8)
|
}, 8)
|
||||||
|
Loading…
Reference in New Issue
Block a user