-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconst.go
165 lines (134 loc) · 3.69 KB
/
const.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
/*
Copyright 2019 yametech.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package canal
import (
"net"
)
var (
Dial = dial
)
type RedisReaderWriter struct {
*reader
*writer
}
func NewRedisReaderWriter(conn net.Conn) *RedisReaderWriter {
return &RedisReaderWriter{
newReader(conn),
newWriter(conn),
}
}
func (r *RedisReaderWriter) ReadValue() (Value, error) {
v, _, err := r.readBulk()
return v, err
}
func (r *RedisReaderWriter) ReadLine() ([]byte, error) {
v, _, err := r.readLine()
return v, err
}
func (r *RedisReaderWriter) Sendcmds(cmd string, args ...interface{}) error {
return r.writeMultiBulk(cmd, args...)
}
// ValueType of redis type
type ValueType byte
// type value
const (
TypeString ValueType = 0
TypeList ValueType = 1
TypeSet ValueType = 2
TypeZSet ValueType = 3
TypeHash ValueType = 4
TypeZSet2 ValueType = 5
TypeModule ValueType = 6
TypeModule2 ValueType = 7
TypeHashZipmap ValueType = 9
TypeListZiplist ValueType = 10
TypeSetIntset ValueType = 11
TypeZSetZiplist ValueType = 12
TypeHashZiplist ValueType = 13
TypeListQuicklist ValueType = 14
TypeStreamListPacks ValueType = 15
)
const (
rdbVersion = 9
rdb6bitLen = 0
rdb14bitLen = 1
rdb32bitLen = 0x80
rdb64bitLen = 0x81
rdbEncVal = 3
//rdbLenErr = math.MaxUint64
rdbOpCodeModuleAux = 247
rdbOpCodeIdle = 248
rdbOpCodeFreq = 249
rdbOpCodeAux = 250
rdbOpCodeResizeDB = 251
rdbOpCodeExpiryMS = 252
rdbOpCodeExpiry = 253
rdbOpCodeSelectDB = 254
rdbOpCodeEOF = 255
//rdbModuleOpCodeEOF = 0
//rdbModuleOpCodeSint = 1
//rdbModuleOpCodeUint = 2
//rdbModuleOpCodeFloat = 3
//rdbModuleOpCodeDouble = 4
//rdbModuleOpCodeString = 5
//
//rdbLoadNone = 0
//rdbLoadEnc = (1 << 0)
//rdbLoadPlain = (1 << 1)
//rdbLoadSds = (1 << 2)
//
//rdbSaveNode = 0
//rdbSaveAofPreamble = (1 << 0)
rdbEncInt8 = 0
rdbEncInt16 = 1
rdbEncInt32 = 2
rdbEncLZF = 3
rdbZiplist6bitlenString = 0
rdbZiplist14bitlenString = 1
rdbZiplist32bitlenString = 2
rdbZiplistInt16 = 0xc0
rdbZiplistInt32 = 0xd0
rdbZiplistInt64 = 0xe0
rdbZiplistInt24 = 0xf0
rdbZiplistInt8 = 0xfe
rdbZiplistInt4 = 15
//rdbLpHdrSize = 6
//rdbLpHdrNumeleUnknown = math.MaxUint16
//rdbLpMaxIntEncodingLen = 0
//rdbLpMaxBacklenSize = 5
//rdbLpMaxEntryBacklen = 34359738367
//rdbLpEncodingInt = 0
//rdbLpEncodingString = 1
rdbLpEncoding7BitUint = 0
rdbLpEncoding7BitUintMask = 0x80
rdbLpEncoding6BitStr = 0x80
rdbLpEncoding6BitStrMask = 0xC0
rdbLpEncoding13BitInt = 0xC0
rdbLpEncoding13BitIntMask = 0xE0
rdbLpEncoding12BitStr = 0xE0
rdbLpEncoding12BitStrMask = 0xF0
rdbLpEncoding16BitInt = 0xF1
rdbLpEncoding16BitIntMask = 0xFF
rdbLpEncoding24BitInt = 0xF2
rdbLpEncoding24BitIntMask = 0xFF
rdbLpEncoding32BitInt = 0xF3
rdbLpEncoding32BitIntMask = 0xFF
rdbLpEncoding64BitInt = 0xF4
rdbLpEncoding64BitIntMask = 0xFF
rdbLpEncoding32BitStr = 0xF0
rdbLpEncoding32BitStrMask = 0xFF
rdbLpEOF = 0xFF
rdbStreamItemFlagNone = 0 /* No special flags. */
//rdbStreamItemFlagDeleted = (1 << 0) /* Entry was deleted. Skip it. */
rdbStreamItemFlangSameFields = (1 << 1) /* Same fields as master entry. */
)