From 962e53af1768b8b7fafe42ec1b7bfeab92c2be9f Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Thu, 21 Mar 2019 10:24:30 +1000 Subject: [PATCH] Add Has() to exported API (extended API) --- bitcask.go | 5 +++++ bitcask_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/bitcask.go b/bitcask.go index b1f27c5..77d7d62 100644 --- a/bitcask.go +++ b/bitcask.go @@ -79,6 +79,11 @@ func (b *Bitcask) Get(key string) ([]byte, error) { return e.Value, nil } +func (b *Bitcask) Has(key string) bool { + _, ok := b.keydir.Get(key) + return ok +} + func (b *Bitcask) Put(key string, value []byte) error { if len(key) > b.config.MaxKeySize { return ErrKeyTooLarge diff --git a/bitcask_test.go b/bitcask_test.go index 98350a4..b6aa0f2 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("Has", func(t *testing.T) { + assert.True(db.Has("foo")) + }) + t.Run("Fold", func(t *testing.T) { var ( keys []string