添加redis/内存流控实现 #1
@ -10,7 +10,6 @@ package abstract
|
||||
import (
|
||||
"context"
|
||||
"git.zhangdeman.cn/zhangdeman/rate_limit/define"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// IRateLimit 流控实现接口约束
|
||||
@ -19,14 +18,6 @@ import (
|
||||
//
|
||||
// Date : 11:33 2024/6/20
|
||||
type IRateLimit interface {
|
||||
// Second(ctx context.Context, key string, total, rate int) (bool, error) // 每秒访问次数限制
|
||||
// Minute(ctx context.Context, key string, total, rate int) (bool, error) // 每分钟访问次数限制
|
||||
// Hour(ctx context.Context, key string, total, rate int) (bool, error) // 每小时访问次数限制
|
||||
// Day(ctx context.Context, key string, total, rate int) (bool, error) // 每天访问次数限制
|
||||
// Month(ctx context.Context, key string, total, rate int) (bool, error) // 每月访问次数限制
|
||||
// Year(ctx context.Context, key string, total, rate int) (bool, error) // 每年访问次数限制
|
||||
// Custom(ctx context.Context, timeInfo int64, key string, total, rate int) (bool, error) // 自定义指定时间内的访问次数, timeInfo 单位 : s
|
||||
SetRedisClient(client *redis.Client) // 设置redis客户端
|
||||
AllowN(ctx context.Context, limitCfg *define.LimitConfig, tokenCnt int) (bool, error) // 申请N个令牌, N >= 0
|
||||
Reset(ctx context.Context, limitCfg *define.LimitConfig) error // 重置
|
||||
}
|
||||
|
14
go.sum
14
go.sum
@ -1,21 +1,11 @@
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7 h1:QR8vMXOTy0NFKdodsGKA4gTNHJMfob3yRFYMXrZj7ek=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240617073616-39e82fd033ed h1:BGv+y6ZdtkxI4HeSIHun0QRrIzjLnUht0bKdyO2t6n4=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240617073616-39e82fd033ed/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y=
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI=
|
||||
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620100925-63e4412d67e1 h1:sI8ON6xfATy12jNLscZnUgnr2SoRRD5eob7Rzc+d1bo=
|
||||
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620100925-63e4412d67e1/go.mod h1:OImVgoNTw9qWxGrgrym0wtEMdx0ekaH7vJJKIgSpdEg=
|
||||
git.zhangdeman.cn/zhangdeman/redis v0.0.0-20240620102217-f11c0a8216f6 h1:2q6yC/vBhDOLLjqziqMJUSuF3bgA3wFDC/swFMOrTPU=
|
||||
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=
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd/go.mod h1:6+7whkCmb4sJDIfH3HxNuXRveaM0gCCNWd2uXZqNtIE=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
|
||||
@ -30,8 +20,6 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
|
||||
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
|
||||
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@ -56,8 +44,6 @@ github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0b
|
||||
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg=
|
||||
github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
|
||||
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
|
Loading…
Reference in New Issue
Block a user