This commit is contained in:
jiangyong 2026-05-08 18:44:38 +08:00
parent d1433040df
commit 49b7b09516
1 changed files with 12 additions and 8 deletions

View File

@ -20,21 +20,25 @@ type WindowsLimit struct {
option *WindowsLimitOption
}
func NewWindowsLimitOption() *WindowsLimitOption {
return &WindowsLimitOption{
Key: fmt.Sprintf("windows:limit:%s:%d", time.Now().Format("20060102"), time.Now().UnixMilli()),
Count: 1000,
Size: time.Second * 60,
}
}
func NewWindowsLimit(client *redis.Client, option *WindowsLimitOption) *WindowsLimit {
option.Default()
return &WindowsLimit{
client: client,
option: option,
}
}
func (o *WindowsLimitOption) Default() {
if o.Key == "" {
o.Key = fmt.Sprintf("windows:limit:%s:%d", time.Now().Format("20060102"), time.Now().UnixMilli())
}
if o.Count <= 0 {
o.Count = 1000
}
if o.Size <= 0 {
o.Size = time.Second * 60
}
}
func (w *WindowsLimit) tidy() {
now := time.Now().UnixMilli()
start := now - w.option.Size.Milliseconds()