-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
57 lines (46 loc) · 1.22 KB
/
store.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
package store
import (
"io"
"time"
)
type (
Store interface {
Close() error
Put(key string, value []byte) error
PutTTL(key string, value []byte, ttl time.Duration) error
Get(key string) ([]byte, error)
TTL(key string) (time.Duration, error)
RPut(key string, r io.Reader, size int64) error
RPutTTL(key string, r io.Reader, size int64, ttl time.Duration) error
RGet(key string) (io.Reader, error)
Exist(key string) (bool, error)
Delete(key string) error
RangeKeys(prefix, limit string, max int) (KeysInfoSlice, error)
Range(prefix, limit string, cb func(key string, value []byte) bool) error
RRange(prefix, limit string, cb func(key string, r io.Reader) bool) error
}
KeysInfo struct {
Key string
Size int64
}
KeysInfoSlice []KeysInfo
)
var (
buckets = map[string]Store{}
)
func Get(bucket string) Store {
return buckets[bucket]
}
func InitStore(bucket string, store Store) {
buckets[bucket] = store
}
var (
_ = Get
_ = InitStore
)
func (s KeysInfoSlice) ToKeys() (result []string) {
for _, info := range s {
result = append(result, info.Key)
}
return
}