-
Notifications
You must be signed in to change notification settings - Fork 0
/
specialCloudScanner.go
52 lines (42 loc) · 1.18 KB
/
specialCloudScanner.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
package scanner
import (
"fmt"
"redis-shake/common"
"redis-shake/configure"
"github.com/garyburd/redigo/redis"
)
type SpecialCloudScanner struct {
client redis.Conn
cursor int64
tencentNodeId string
aliyunNodeId int
}
func (scs *SpecialCloudScanner) ScanKey() ([]string, error) {
var (
values []interface{}
err error
keys []string
)
switch conf.Options.ScanSpecialCloud {
case utils.TencentCluster:
values, err = redis.Values(scs.client.Do("SCAN", scs.cursor, "COUNT",
conf.Options.ScanKeyNumber, scs.tencentNodeId))
case utils.AliyunCluster:
values, err = redis.Values(scs.client.Do("ISCAN", scs.aliyunNodeId, scs.cursor, "COUNT",
conf.Options.ScanKeyNumber))
}
if err != nil && err != redis.ErrNil {
return nil, fmt.Errorf("SpecialCloudScanner: scan with cursor[%v] failed[%v]", scs.cursor, err)
}
values, err = redis.Scan(values, &scs.cursor, &keys)
if err != nil && err != redis.ErrNil {
return nil, fmt.Errorf("SpecialCloudScanner: do scan with cursor[%v] failed[%v]", scs.cursor, err)
}
return keys, nil
}
func (scs *SpecialCloudScanner) EndNode() bool {
return scs.cursor == 0
}
func (scs *SpecialCloudScanner) Close() {
scs.client.Close()
}