mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Add Keys() to exported API (extended API)
This commit is contained in:
parent
01cb269a51
commit
aaea7273c3
@ -125,6 +125,10 @@ func (b *Bitcask) Scan(prefix string, f func(key string) error) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bitcask) Keys() chan string {
|
||||||
|
return b.keydir.Keys()
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Bitcask) Fold(f func(key string) error) error {
|
func (b *Bitcask) Fold(f func(key string) error) error {
|
||||||
for key := range b.keydir.Keys() {
|
for key := range b.keydir.Keys() {
|
||||||
if err := f(key); err != nil {
|
if err := f(key); err != nil {
|
||||||
|
@ -44,6 +44,14 @@ func TestAll(t *testing.T) {
|
|||||||
assert.True(db.Has("foo"))
|
assert.True(db.Has("foo"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Keys", func(t *testing.T) {
|
||||||
|
keys := make([]string, 0)
|
||||||
|
for key := range db.Keys() {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
assert.Equal([]string{"foo"}, keys)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Fold", func(t *testing.T) {
|
t.Run("Fold", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
keys []string
|
keys []string
|
||||||
|
@ -55,8 +55,10 @@ func (k *Keydir) Delete(key string) {
|
|||||||
func (k *Keydir) Keys() chan string {
|
func (k *Keydir) Keys() chan string {
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
for k := range k.kv {
|
k.RLock()
|
||||||
ch <- k
|
defer k.RUnlock()
|
||||||
|
for key := range k.kv {
|
||||||
|
ch <- key
|
||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user