From 1ece19709e8735dbca66abbcd668cb676db58bef Mon Sep 17 00:00:00 2001 From: Kleissner Date: Sat, 11 Dec 2021 13:00:49 +0100 Subject: [PATCH] Store: New Count() function to return count of all records stored. --- store/Memory.go | 7 +++++++ store/Pogreb.go | 5 +++++ store/Store.go | 3 +++ 3 files changed, 15 insertions(+) diff --git a/store/Memory.go b/store/Memory.go index a135959..c47f806 100644 --- a/store/Memory.go +++ b/store/Memory.go @@ -71,3 +71,10 @@ func (ms *MemoryStore) Delete(key []byte) { delete(ms.data, string(key)) ms.mutex.Unlock() } + +// Count returns the count of records stored. +func (ms *MemoryStore) Count() uint64 { + ms.mutex.Lock() + defer ms.mutex.Unlock() + return uint64(len(ms.data)) +} diff --git a/store/Pogreb.go b/store/Pogreb.go index 67ba2ef..0ff49cc 100644 --- a/store/Pogreb.go +++ b/store/Pogreb.go @@ -69,3 +69,8 @@ func (store *PogrebStore) Get(key []byte) (data []byte, found bool) { func (store *PogrebStore) Delete(key []byte) { store.db.Delete(key) } + +// Count returns the count of records stored. +func (store *PogrebStore) Count() uint64 { + return uint64(store.db.Count()) +} diff --git a/store/Store.go b/store/Store.go index 08a0e8c..13a9688 100644 --- a/store/Store.go +++ b/store/Store.go @@ -29,4 +29,7 @@ type Store interface { // ExpireKeys is called to delete all keys that are marked for expiration. ExpireKeys() + + // Count returns the total number of records stored. + Count() uint64 }