-
Notifications
You must be signed in to change notification settings - Fork 2
/
kv.go
92 lines (77 loc) · 1.98 KB
/
kv.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
package corekv
import "context"
// DefaultIterOptions is exactly the default zero value
// for the IterOptions stuct. It is however recomended
// to use this if you want the "default" behavior, as
// these values may change in some way in the future
// and the old "default" as zero values may produce
// different behavior.
var DefaultIterOptions = IterOptions{}
type IterOptions struct {
// Prefix iteration, all keys *must* contain
// the designated prefix. Prefix takes precendent
// over range (start/end). If Prefix is nil, range
// will be used (regardless if start/end is nil)
Prefix []byte
// Range iteration from start (inclusive) to end explusive.
// Start must be lexigraphically less
// then end, unless `nil` is used.
//
// Start defined as nil will iterate from the first
// key in the store.
// End defined as nil will iterate till the last key
// in the store.
Start []byte
End []byte
// Reverse the direction of the iteration.
Reverse bool
// Only iterate through keys. Calling Value() on the
// iterator *must* return nil (no error).
KeysOnly bool
}
type Reader interface {
Get(ctx context.Context, key []byte) ([]byte, error)
Has(ctx context.Context, key []byte) (bool, error)
Iterator(ctx context.Context, opts IterOptions) Iterator
}
type Writer interface {
Set(ctx context.Context, key, value []byte) error
Delete(ctx context.Context, key []byte) error
}
type Iterator interface {
Domain() (start []byte, end []byte)
Valid() bool
Next()
Key() []byte
Value() ([]byte, error)
Seek([]byte)
Close(ctx context.Context) error
}
type Store interface {
Reader
Writer
Close() error
}
type Batchable interface {
Store
NewBatch() Batch
}
type Batch interface {
Writer
Write(context.Context) error
Close(context.Context) error
}
type TxnStore interface {
Store
NewTxn(readonly bool) Txn
}
type Txn interface {
Reader
Writer
Commit(ctx context.Context) error
Discard(ctx context.Context) error
}
type Item interface {
Key() []byte
Value() []byte
}