-
Notifications
You must be signed in to change notification settings - Fork 9
/
core_string.go
66 lines (58 loc) · 1.82 KB
/
core_string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package nutshttp
import "github.com/xujiajun/nutsdb"
// Update handle insert and update operation
func (c *core) Update(bucket string, key string, value string, ttl uint32) error {
err := c.db.Update(func(tx *nutsdb.Tx) error {
err := tx.Put(bucket, []byte(key), []byte(value), ttl)
return err
})
return err
}
// Delete handle delete operation
func (c *core) Delete(bucket string, key string) error {
err := c.db.Update(func(tx *nutsdb.Tx) error {
err := tx.Delete(bucket, []byte(key))
return err
})
return err
}
// Get handle get key operation
func (c *core) Get(bucket string, key string) (value string, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
entry, err := tx.Get(bucket, []byte(key))
if err != nil {
return err
}
value = string(entry.Value)
return nil
})
return value, err
}
func (c *core) PrefixScan(bucket string, prefix string, offSet int, limNum int) (entries nutsdb.Entries, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
entries, _, err = tx.PrefixScan(bucket, []byte(prefix), offSet, limNum)
return err
})
return entries, err
}
func (c *core) PrefixSearchScan(bucket, prefix string, reg string, offSet int, limNum int) (entries nutsdb.Entries, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
entries, _, err = tx.PrefixSearchScan(bucket, []byte(prefix), reg, offSet, limNum)
return err
})
return entries, err
}
func (c *core) RangeScan(bucket string, start string, end string) (entries nutsdb.Entries, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
entries, err = tx.RangeScan(bucket, []byte(start), []byte(end))
return err
})
return entries, err
}
func (c *core) GetAll(bucket string) (entries nutsdb.Entries, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
entries, err = tx.GetAll(bucket)
return err
})
return entries, err
}