fix: counter 包修复 mark key 无法被清理、重置的问题
This commit is contained in:
parent
64ecd459a1
commit
a31369abbe
|
@ -124,6 +124,15 @@ func (slf *Counter[K, V]) Reset(key K) {
|
||||||
slf.lock.Unlock()
|
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 的过期时间
|
// ResetExpired 重置特定 key 的过期时间
|
||||||
func (slf *Counter[K, V]) ResetExpired(key K) {
|
func (slf *Counter[K, V]) ResetExpired(key K) {
|
||||||
slf.lock.Lock()
|
slf.lock.Lock()
|
||||||
|
@ -131,11 +140,20 @@ func (slf *Counter[K, V]) ResetExpired(key K) {
|
||||||
slf.lock.Unlock()
|
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 重置所有计数
|
// ResetAll 重置所有计数
|
||||||
func (slf *Counter[K, V]) ResetAll() {
|
func (slf *Counter[K, V]) ResetAll() {
|
||||||
slf.lock.Lock()
|
slf.lock.Lock()
|
||||||
clear(slf.c)
|
clear(slf.c)
|
||||||
clear(slf.dr)
|
clear(slf.dr)
|
||||||
|
clear(slf.drm)
|
||||||
slf.lock.Unlock()
|
slf.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue