Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Kilibaba committed Apr 15, 2019
1 parent 4721544 commit e84be80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
19 changes: 14 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pudge
import (
"bytes"
"encoding/gob"
"log"
"os"
)

Expand Down Expand Up @@ -321,21 +322,29 @@ func (db *Db) Keys(from interface{}, limit, offset int, asc bool) ([][]byte, err
excludeFrom = 1

k, err := KeyToBinary(from)
log.Println(bytes.Equal(k[len(k)-1:], []byte("*")))
if err != nil {
return arr, err
}
if len(k) > 1 && bytes.Equal(k[len(k)-1:], []byte("*")) {
prefix := make([]byte, len(k)-1)
copy(prefix, k)
return db.KeysByPrefix(prefix, limit, offset, asc)
byteOrStr := false
switch from.(type) {
case []byte:
byteOrStr = true
case string:
byteOrStr = true
}
if byteOrStr {
prefix := make([]byte, len(k)-1)
copy(prefix, k)
return db.KeysByPrefix(prefix, limit, offset, asc)
}
}
}
db.RLock()
defer db.RUnlock()

find, _ := db.findKey(from, asc)
start, end := checkInterval(find, limit, offset, excludeFrom, len(db.keys), asc)
//log.Println(from, find, start, end)
if start < 0 || start >= len(db.keys) {
return arr, nil
}
Expand Down
16 changes: 16 additions & 0 deletions pudge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,19 @@ func TestInMemoryWithoutPersist(t *testing.T) {
}

}

func Test42(t *testing.T) {
DefaultConfig.StoreMode = 0
f := "test/int64"
for i := 1; i < 64; i++ {
Set(f, int64(i), int64(i))
}
keys, err := Keys(f, int64(42), 100, 0, true)
if err != nil {
t.Error(err)
}
if len(keys) != 22 {
t.Error("not 21", len(keys))
}
DeleteFile(f)
}

0 comments on commit e84be80

Please sign in to comment.