Add Has() to exported API (extended API)

This commit is contained in:
James Mills 2019-03-21 10:24:30 +10:00
parent 7a427a237a
commit 962e53af17
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
2 changed files with 9 additions and 0 deletions

@ -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

@ -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