fix: counter 包修复 mark key 无法被清理、重置的问题

This commit is contained in:
kercylan98 2023-08-21 16:40:09 +08:00
parent 64ecd459a1
commit a31369abbe
1 changed files with 18 additions and 0 deletions

View File

@ -124,6 +124,15 @@ func (slf *Counter[K, V]) Reset(key K) {
slf.lock.Unlock()
}
// ResetMark 重置特定 mark 的 key 的计数
func (slf *Counter[K, V]) ResetMark(mark, key K) {
slf.lock.Lock()
mk := fmt.Sprintf("%v_%v", mark, key)
delete(slf.c, key)
delete(slf.drm, mk)
slf.lock.Unlock()
}
// ResetExpired 重置特定 key 的过期时间
func (slf *Counter[K, V]) ResetExpired(key K) {
slf.lock.Lock()
@ -131,11 +140,20 @@ func (slf *Counter[K, V]) ResetExpired(key K) {
slf.lock.Unlock()
}
// ResetExpiredMark 重置特定 mark 的 key 的过期时间
func (slf *Counter[K, V]) ResetExpiredMark(mark, key K) {
slf.lock.Lock()
mk := fmt.Sprintf("%v_%v", mark, key)
delete(slf.drm, mk)
slf.lock.Unlock()
}
// ResetAll 重置所有计数
func (slf *Counter[K, V]) ResetAll() {
slf.lock.Lock()
clear(slf.c)
clear(slf.dr)
clear(slf.drm)
slf.lock.Unlock()
}