-
Notifications
You must be signed in to change notification settings - Fork 0
/
define.go
236 lines (189 loc) · 4.82 KB
/
define.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package storager
import (
"errors"
"math"
)
// For different const size configuration
const (
// max allowed databases
MaxDatabases int = 10240
// max key size
MaxKeySize int = 1024
// max hash field size
MaxHashFieldSize int = 1024
// max zset member size
MaxZSetMemberSize int = 1024
// max set member size
MaxSetMemberSize int = 1024
// max value size
MaxValueSize int = 1024 * 1024 * 1024
// default scan count
DefaultScanCount int = 10
)
// DataType is defined for the different types
type DataType byte
// for out use
const (
STRING DataType = iota
LIST
HASH
SET
ZSET
BITMAP
)
// For different type name
const (
StringName = "STRING"
ListName = "LIST"
HashName = "HASH"
SetName = "SET"
ZSetName = "ZSET"
BitmapName = "BITMAP"
)
func (d DataType) String() string {
switch d {
case STRING:
return StringName
case LIST:
return ListName
case HASH:
return HashName
case SET:
return SetName
case ZSET:
return ZSetName
case BITMAP:
return BitmapName
default:
return "unknown"
}
}
// for backend store key
// notice: Please add new type in order
const (
NoneType byte = iota
StringType
HSizeType
HashType
LMetaType
ListType
SSizeType
SetType
ZSizeType
ZSetType
ZScoreType
ExpTimeType
ExpMetaType
BitmapType
maxDataType byte = 100
)
// TypeName is the map of type -> name
var TypeName = map[byte]string{
StringType: "string",
HashType: "hash",
HSizeType: "hsize",
ListType: "list",
LMetaType: "lmeta",
SetType: "set",
SSizeType: "ssize",
ZSetType: "zset",
ZSizeType: "zsize",
ZScoreType: "zscore",
ExpTimeType: "exptime",
ExpMetaType: "expmeta",
BitmapType: "bitmap",
}
var (
ErrValueIntOutOfRange = errors.New("ERR value is not an integer or out of range")
ErrIntNumber = errors.New("ERR invalid integer")
ErrKeySize = errors.New("ERR invalid key size")
ErrValueSize = errors.New("ERR invalid value size")
ErrExpireValue = errors.New("ERR invalid expire value")
ErrStringKey = errors.New("ERR invalid encode string key")
ErrLMetaKey = errors.New("ERR invalid lmeta key")
ErrListKey = errors.New("ERR invalid list key")
ErrListSeq = errors.New("ERR invalid list sequence, overflow")
ErrListIndex = errors.New("ERR invalid list index")
ErrHashKey = errors.New("ERR invalid hash key")
ErrHashIntVal = errors.New("ERR hash value is not an integer")
ErrHSizeKey = errors.New("ERR invalid hsize key")
ErrHashFieldSize = errors.New("ERR invalid hash field size")
ErrSetKey = errors.New("ERR invalid set key")
ErrSSizeKey = errors.New("ERR invalid ssize key")
ErrSetMemberSize = errors.New("ERR invalid set member size")
ErrZSizeKey = errors.New("ERR invalid zsize key")
ErrZSetKey = errors.New("ERR invalid zset key")
ErrZScoreKey = errors.New("ERR invalid zscore key")
ErrScoreOverflow = errors.New("ERR zset score overflow")
ErrInvalidAggregate = errors.New("ERR invalid aggregate")
ErrInvalidWeightNum = errors.New("ERR invalid weight number")
ErrInvalidSrcKeyNum = errors.New("ERR invalid src key number")
ErrZSetMemberSize = errors.New("ERR invalid zset member size")
ErrExpMetaKey = errors.New("ERR invalid expire meta key")
ErrExpTimeKey = errors.New("ERR invalid expire time key")
ErrDataType = errors.New("ERR invalid data type")
ErrMetaKey = errors.New("ERR invalid meta key")
ErrBitmapKey = errors.New("ERR invalid encode bitmap key")
// For different common errors
ErrScoreMiss = errors.New("ERR zset score miss")
// For slots
ErrUnsupportSlots = errors.New("unsupport slots")
ErrKeyNotFound = errors.New("key not found")
)
// For list op
const (
listHeadSeq int32 = 1
listTailSeq int32 = 2
listMinSeq int32 = 1000
listMaxSeq int32 = 1<<31 - 1000
listInitialSeq int32 = listMinSeq + (listMaxSeq-listMinSeq)/2
)
// For hash op
const (
hashStartSep byte = ':'
hashStopSep byte = hashStartSep + 1
)
// For set op
const (
setStartSep byte = ':'
setStopSep byte = setStartSep + 1
UnionType byte = 51
DiffType byte = 52
InterType byte = 53
)
// For zset op
const (
MinScore int64 = math.MinInt64 + 1
MaxScore int64 = math.MaxInt64
InvalidScore int64 = math.MinInt64
AggregateSum = "sum"
AggregateMin = "min"
AggregateMax = "max"
zsetNScoreSep byte = '<'
zsetPScoreSep byte = zsetNScoreSep + 1
zsetStopScoreSep byte = zsetPScoreSep + 1
zsetStartMemSep byte = ':'
zsetStopMemSep byte = zsetStartMemSep + 1
)
// For bit operation
const (
BitAND = "and"
BitOR = "or"
BitXOR = "xor"
BitNot = "not"
)
const (
RegisterStoragerName = "xdis-storager"
)
// MaxVarintLenN is the maximum length of a varint-encoded N-bit integer.
const (
MaxVarintLen16 = 3
MaxVarintLen32 = 5
// the most size for varint is 10 bytes
MaxVarintLen64 = 10
)
const (
CodeTypeMeta byte = '@'
CodeTypeData byte = '$'
Version byte = 0
)