-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
135 lines (113 loc) · 3.36 KB
/
db.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package redibolt
import bolt "go.etcd.io/bbolt"
type db struct {
boltDB *bolt.DB
}
func NewDB(boltDB *bolt.DB) DB {
return &db{boltDB}
}
func (db *db) MULTIUPDATE(f func(tx Tx) error) error {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return f(NewTx(tx))
})
}
func (db *db) MULTIREAD(f func(tx ReadTx) error) error {
return db.boltDB.View(func(tx *bolt.Tx) error {
return f(NewTx(tx))
})
}
func (db *db) DEL(key ...string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).DEL(key...)
})
}
func (db *db) HDEL(key string, field string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).HDEL(key, field)
})
}
func (db *db) HEXISTS(key string, field string) (exists bool, err error) {
return exists, db.boltDB.View(func(tx *bolt.Tx) error {
exists, err = NewTx(tx).HEXISTS(key, field)
return err
})
}
func (db *db) HGET(key string, field string) (val string, err error) {
return val, db.boltDB.View(func(tx *bolt.Tx) error {
val, err = NewTx(tx).HGET(key, field)
return err
})
}
func (db *db) HGETALL(key string) (kvMap map[string]string, err error) {
return kvMap, db.boltDB.View(func(tx *bolt.Tx) error {
kvMap, err = NewTx(tx).HGETALL(key)
return err
})
}
func (db *db) HKEYS(key string) (keys []string, err error) {
return keys, db.boltDB.View(func(tx *bolt.Tx) error {
keys, err = NewTx(tx).HKEYS(key)
return err
})
}
func (db *db) HLEN(key string) (count int, err error) {
return count, db.boltDB.View(func(tx *bolt.Tx) error {
count, err = NewTx(tx).HLEN(key)
return err
})
}
func (db *db) HMGET(key string, fields ...string) (vals []string, err error) {
return vals, db.boltDB.View(func(tx *bolt.Tx) error {
vals, err = NewTx(tx).HMGET(key, fields...)
return err
})
}
func (db *db) HMSET(key string, fields map[string]string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).HMSET(key, fields)
})
}
func (db *db) HSET(key string, field string, value string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).HSET(key, field, value)
})
}
func (db *db) SADD(key string, members ...string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).SADD(key, members...)
})
}
func (db *db) SCARD(key string) (count int, err error) {
return count, db.boltDB.View(func(tx *bolt.Tx) error {
count, err = NewTx(tx).SCARD(key)
return err
})
}
func (db *db) SISMEMBER(key string, member string) (isMember bool, err error) {
return isMember, db.boltDB.View(func(tx *bolt.Tx) error {
isMember, err = NewTx(tx).SISMEMBER(key, member)
return err
})
}
func (db *db) SMEMBERS(key string) (members []string, err error) {
return members, db.boltDB.View(func(tx *bolt.Tx) error {
members, err = NewTx(tx).SMEMBERS(key)
return err
})
}
func (db *db) SREM(key string, member ...string) (err error) {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).SREM(key, member...)
})
}
func (db *db) SMOVE(source string, destination string, member string) error {
return db.boltDB.Update(func(tx *bolt.Tx) error {
return NewTx(tx).SMOVE(source, destination, member)
})
}
func (db *db) SDIFF(key string, diffKeys ...string) (members []string, err error) {
return members, db.boltDB.View(func(tx *bolt.Tx) error {
members, err = NewTx(tx).SDIFF(key, diffKeys...)
return err
})
}