From 40bfaafa5a6a7a344753deec656963349385fef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 20 Jun 2024 18:48:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E5=AE=8C=E6=88=90redis?= =?UTF-8?q?=E6=B5=81=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 2 ++ redis_test.go | 30 +++++------------------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index d0d7c33..b3e5537 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 6c3cd3e..d17a7a5 100644 --- a/go.sum +++ b/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-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= diff --git a/redis_test.go b/redis_test.go index 6b8c6a0..fc36fbc 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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)