diff --git a/bitcask.go b/bitcask.go index 8f28878..02a6ef5 100644 --- a/bitcask.go +++ b/bitcask.go @@ -125,6 +125,10 @@ func (b *Bitcask) Scan(prefix string, f func(key string) error) error { return nil } +func (b *Bitcask) Len() int { + return b.keydir.Len() +} + func (b *Bitcask) Keys() chan string { return b.keydir.Keys() } diff --git a/bitcask_test.go b/bitcask_test.go index c343f06..d1d542c 100644 --- a/bitcask_test.go +++ b/bitcask_test.go @@ -40,6 +40,10 @@ func TestAll(t *testing.T) { assert.Equal([]byte("bar"), val) }) + t.Run("Len", func(t *testing.T) { + assert.Equal(1, db.Len()) + }) + t.Run("Has", func(t *testing.T) { assert.True(db.Has("foo")) }) diff --git a/internal/keydir.go b/internal/keydir.go index 285d16b..1f60c4c 100644 --- a/internal/keydir.go +++ b/internal/keydir.go @@ -52,6 +52,10 @@ func (k *Keydir) Delete(key string) { delete(k.kv, key) } +func (k *Keydir) Len() int { + return len(k.kv) +} + func (k *Keydir) Keys() chan string { ch := make(chan string) go func() {