redis流控测试

This commit is contained in:
2024-06-20 18:43:27 +08:00
parent 54a77d170a
commit 545523e324
5 changed files with 21 additions and 18 deletions

View File

@ -14,16 +14,14 @@ import (
wrapRedis "git.zhangdeman.cn/zhangdeman/redis"
wrapRedisDefine "git.zhangdeman.cn/zhangdeman/redis/define"
"testing"
"time"
)
func TestRedis_AllowN(t *testing.T) {
_ = wrapRedis.Client.AddClient("test_rate_limit", &wrapRedisDefine.ClusterOptions{
Addrs: []string{"127.0.0.1:6379"},
_ = wrapRedis.Client.AddClient("test_rate_limit", &wrapRedisDefine.Options{
Addr: "127.0.0.1:6379",
Network: "TCP",
ClientName: "",
MaxRedirects: 0,
ReadOnly: false,
RouteByLatency: false,
RouteRandomly: false,
Protocol: 0,
Username: "",
Password: "123456",
@ -46,11 +44,14 @@ func TestRedis_AllowN(t *testing.T) {
IdentitySuffix: "",
})
RedisClient.SetRedisClient(wrapRedis.Client.GetRealClient("test_rate_limit"))
allow, err := RedisClient.AllowN(context.Background(), &define.LimitConfig{
Key: "deman",
Total: 600,
Rate: 10,
TimeInterval: 60,
}, 8)
fmt.Println(allow, err)
for i := 0; i < 100; i++ {
allow, err := RedisClient.AllowN(context.Background(), &define.LimitConfig{
Key: "deman",
Total: 600,
Rate: 10,
TimeInterval: 60,
}, 8)
fmt.Println(allow, err)
time.Sleep(time.Second)
}
}