-
Notifications
You must be signed in to change notification settings - Fork 9
/
core_list.go
112 lines (97 loc) · 2.58 KB
/
core_list.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package nutshttp
import "github.com/xujiajun/nutsdb"
func (c *core) LRange(bucket string, key string, start, end int) ([]string, error) {
var items []string
err := c.db.Update(func(tx *nutsdb.Tx) (err error) {
itemsBytes, err := tx.LRange(bucket, []byte(key), start, end)
if err == nil {
for _, itemByte := range itemsBytes {
items = append(items, string(itemByte))
}
}
return err
})
return items, err
}
func (c *core) RPush(bucket, key, value string) error {
err := c.db.Update(func(tx *nutsdb.Tx) error {
err := tx.RPush(bucket, []byte(key), []byte(value))
return err
})
return err
}
func (c *core) LPush(bucket, key, value string) error {
err := c.db.Update(func(tx *nutsdb.Tx) error {
err := tx.LPush(bucket, []byte(key), []byte(value))
return err
})
return err
}
func (c *core) RPop(bucket, key string) (value string, err error) {
err = c.db.Update(func(tx *nutsdb.Tx) error {
resByte, err := tx.RPop(bucket, []byte(key))
if err == nil {
value = string(resByte)
}
return err
})
return value, err
}
func (c *core) LPop(bucket, key string) (value string, err error) {
err = c.db.Update(func(tx *nutsdb.Tx) error {
resByte, err := tx.RPop(bucket, []byte(key))
if err == nil {
value = string(resByte)
}
return err
})
return value, err
}
func (c *core) RPeek(bucket, key string) (value string, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
resByte, err := tx.RPeek(bucket, []byte(key))
if err == nil {
value = string(resByte)
}
return nil
})
return value, err
}
func (c *core) LPeek(bucket, key string) (value string, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
resByte, err := tx.LPeek(bucket, []byte(key))
if err == nil {
value = string(resByte)
}
return nil
})
return value, err
}
func (c *core) LRem(bucket, key, value string, count int) (num int, err error) {
err = c.db.Update(func(tx *nutsdb.Tx) error {
num, err = tx.LRem(bucket, []byte(key), count, []byte(value))
return err
})
return num, err
}
func (c *core) LSet(bucket, key, value string, index int) (err error) {
err = c.db.Update(func(tx *nutsdb.Tx) error {
err = tx.LSet(bucket, []byte(key), index, []byte(value))
return err
})
return err
}
func (c *core) LTrim(bucket, key string, start, end int) (err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
err = tx.LTrim(bucket, []byte(key), start, end)
return err
})
return err
}
func (c *core) LSize(bucket, key string) (size int, err error) {
err = c.db.View(func(tx *nutsdb.Tx) error {
size, err = tx.LSize(bucket, []byte(key))
return err
})
return size, err
}