Skip to content

Commit edbbcd4

Browse files
authored
Merge pull request #90 from ucwong/dev
deps & nutsdb test
2 parents c698b8d + dfd0e0c commit edbbcd4

File tree

3 files changed

+132
-7
lines changed

3 files changed

+132
-7
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ module github.com/ucwong/golang-kv
33
go 1.20
44

55
require (
6-
github.com/cockroachdb/pebble v0.0.0-20230519195609-e892f45bc7e2
6+
github.com/cockroachdb/pebble v0.0.0-20230522192619-7a5a70ca34f5
77
github.com/dgraph-io/badger/v4 v4.0.2-0.20230519043050-44b59785a8cd
88
github.com/nutsdb/nutsdb v0.12.3-0.20230521084054-b0a6e1ba0c39
99
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
1010
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb
11-
go.etcd.io/bbolt v1.3.7-0.20230518005001-07579acf0c9a
11+
go.etcd.io/bbolt v1.3.7-0.20230522234353-d5339652fb36
1212
)
1313

1414
require (

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZO
3232
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
3333
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
3434
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
35-
github.com/cockroachdb/pebble v0.0.0-20230519195609-e892f45bc7e2 h1:MnVO2CIKkGvP82UJopWja6nw7GZsxVLUKWGtzTKYa5I=
36-
github.com/cockroachdb/pebble v0.0.0-20230519195609-e892f45bc7e2/go.mod h1:TkdVsGYRqtULUppt2RbC+YaKtTHnHoWa2apfFrSKABw=
35+
github.com/cockroachdb/pebble v0.0.0-20230522192619-7a5a70ca34f5 h1:c4ApANlXVl2qP72acWsbeKoGjMizUpNVJ1EVTuboVDg=
36+
github.com/cockroachdb/pebble v0.0.0-20230522192619-7a5a70ca34f5/go.mod h1:TkdVsGYRqtULUppt2RbC+YaKtTHnHoWa2apfFrSKABw=
3737
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
3838
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
3939
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
@@ -259,7 +259,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
259259
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
260260
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
261261
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
262-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
262+
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
263263
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs=
264264
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
265265
github.com/ucwong/go-ttlmap v1.0.2-0.20221020173635-331e7ddde2bb h1:dVZH3AH9f7zB3VBmsjn25B7lfcAyMP4QxdFYTrfj7tg=
@@ -290,8 +290,8 @@ github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZ
290290
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
291291
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
292292
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
293-
go.etcd.io/bbolt v1.3.7-0.20230518005001-07579acf0c9a h1:ujWV+qUt0smDnhcCocmcKP3ZlxSp4AiZeP1rkN0qU7I=
294-
go.etcd.io/bbolt v1.3.7-0.20230518005001-07579acf0c9a/go.mod h1:Gpl72SbxgstRmiprmz97EAQ8YY0qrKG6jHQEVYP+DKY=
293+
go.etcd.io/bbolt v1.3.7-0.20230522234353-d5339652fb36 h1:OVEZ3S3fOh0o5zKwoLvJ5nQnyWeIZfl0rGci8kOEBEc=
294+
go.etcd.io/bbolt v1.3.7-0.20230522234353-d5339652fb36/go.mod h1:PvuFZP/XX446CNNHwxZFAWovpN1kD+b0YgX0o4FaCvI=
295295
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
296296
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
297297
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=

nutsdb/nutsdb_test.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright (C) 2022 ucwong
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with this program. If not, see <https://www.gnu.org/licenses/>
15+
16+
package nutsdb
17+
18+
import (
19+
"fmt"
20+
//"github.com/ucwong/golang-kv"
21+
"strconv"
22+
"testing"
23+
"time"
24+
)
25+
26+
func TestLocal(t *testing.T) {
27+
nutsdb1()
28+
}
29+
30+
var batch int = 10
31+
32+
func nutsdb1() {
33+
34+
db := Open("")
35+
if db == nil {
36+
panic("nutsdb create err")
37+
}
38+
db.Set([]byte("yx"), []byte("yx"))
39+
db.Set([]byte("yy"), []byte("yy"))
40+
db.Set([]byte("a"), []byte("a"))
41+
db.Set([]byte("b"), []byte("b"))
42+
db.Set([]byte("x"), []byte("x"))
43+
db.Set([]byte("y"), []byte("y"))
44+
db.Set([]byte("xxy"), []byte("xxy"))
45+
db.Set([]byte("xxx"), []byte("xxx"))
46+
db.Set([]byte("xxxyx"), []byte("xxxyx"))
47+
db.Set([]byte("xyy"), []byte("xyy"))
48+
db.SetTTL([]byte("ttlxxxyx"), []byte("ttlxxxyx"), 1000*time.Millisecond)
49+
db.Set([]byte("ttlxxxyx"), []byte("ttlxxxyx"))
50+
db.SetTTL([]byte("ttlxxxyx1"), []byte("ttlxxxyx1"), 200000*time.Millisecond)
51+
db.SetTTL([]byte("ttlxxxyx2"), []byte("ttlxxxyx2"), 5000*time.Millisecond)
52+
db.SetTTL([]byte("ttlxxxyx3"), []byte("ttlxxxyx3"), 5000*time.Millisecond)
53+
for i := 0; i < batch; i++ {
54+
db.SetTTL([]byte("ttlxxxyx3"+strconv.Itoa(i)), []byte("ttlxxxyx3"+strconv.Itoa(i)), 2000*time.Millisecond)
55+
}
56+
for i := 0; i < batch; i++ {
57+
db.SetTTL([]byte("ttlxxxyx4"+strconv.Itoa(i)), []byte("ttlxxxyx4"+strconv.Itoa(i)), 5000*time.Millisecond)
58+
}
59+
res := db.Scan()
60+
for _, i := range res {
61+
fmt.Printf("scan...%v...%s\n", len(res), string(i))
62+
}
63+
res = db.Range([]byte("xxx"), []byte("xxz"))
64+
for _, i := range res {
65+
fmt.Printf("range...%v...%s\n", len(res), string(i))
66+
}
67+
res = db.Prefix([]byte("xx"))
68+
for _, i := range res {
69+
fmt.Printf("prefix...%v...%s\n", len(res), string(i))
70+
}
71+
res = db.Suffix([]byte("x"))
72+
for _, i := range res {
73+
fmt.Printf("suffix...%v...%s\n", len(res), string(i))
74+
}
75+
kvs := make(map[string][]byte)
76+
kvs["batch1"] = []byte("batchv1")
77+
kvs["batch2"] = []byte("batchv2")
78+
kvs["batch3"] = []byte("batchv3")
79+
kvs["batch4"] = []byte("batchv4")
80+
db.BatchSet(kvs)
81+
res = db.Prefix([]byte("batch"))
82+
for _, i := range res {
83+
fmt.Printf("prefix(batch)...%v...%s\n", len(res), string(i))
84+
}
85+
res = db.Scan()
86+
for _, i := range res {
87+
fmt.Printf("scan...%v...%v\n", len(res), len(i))
88+
}
89+
//db.Del([]byte("xxy"))
90+
//res = db.Scan()
91+
//for _, i := range res {
92+
// fmt.Printf("...%v...%s\n", len(res), string(i))
93+
//}
94+
db.Del([]byte("xx"))
95+
time.Sleep(500 * time.Millisecond)
96+
f := db.Get([]byte("ttlxxxyx"))
97+
fmt.Printf("...........%s\n", string(f))
98+
99+
f1 := db.Get([]byte("xxy"))
100+
fmt.Printf("...........%s\n", string(f1))
101+
102+
for i := 0; i < batch/2; i++ {
103+
db.Set([]byte("ttlxxxyx4"+strconv.Itoa(i)), []byte("reset -> ttlxxxyx4"+strconv.Itoa(i)))
104+
}
105+
106+
for i := 0; i < batch; i++ {
107+
fmt.Printf("...........%s\n", string(db.Get([]byte("ttlxxxyx4"+strconv.Itoa(i)))))
108+
}
109+
110+
db.Del([]byte("ttlxxxyx1"))
111+
112+
time.Sleep(3000 * time.Millisecond)
113+
m := db.Get([]byte("ttlxxxyx"))
114+
fmt.Printf("...........%s\n", string(m))
115+
116+
db.Del([]byte("ttlxxxyx1"))
117+
118+
m2 := db.Get([]byte("ttlxxxyx1"))
119+
fmt.Printf("...........%s\n", string(m2))
120+
121+
f2 := db.Get([]byte("xxy"))
122+
fmt.Printf("...........%s\n", string(f2))
123+
fmt.Printf("Close func call\n")
124+
db.Close()
125+
}

0 commit comments

Comments
 (0)