feat: prioritize DBS over cluster enabled in scan mode (#855)

This commit is contained in:
suxb201 2024-08-28 22:17:40 +08:00 committed by GitHub
parent f1c46964c5
commit 6093348dcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 10 deletions

View File

@ -64,25 +64,24 @@ func NewScanStandaloneReader(ctx context.Context, opts *ScanReaderOptions) Reade
r := new(scanStandaloneReader)
// dbs
c := client.NewRedisClient(ctx, opts.Address, opts.Username, opts.Password, opts.Tls, opts.PreferReplica)
if c.IsCluster() { // not use opts.Cluster, because user may use standalone mode to scan a cluster node
if len(opts.DBS) != 0 {
r.dbs = opts.DBS
} else if c.IsCluster() { // not use opts.Cluster, because user may use standalone mode to scan a cluster node
r.dbs = []int{0}
} else {
if len(opts.DBS) == 0 {
c.Send("info", "keyspace")
info, err := c.Receive()
if err != nil {
log.Panicf(err.Error())
}
r.dbs = utils.ParseDBs(info.(string))
} else {
r.dbs = opts.DBS
c.Send("info", "keyspace")
info, err := c.Receive()
if err != nil {
log.Panicf(err.Error())
}
r.dbs = utils.ParseDBs(info.(string))
}
r.opts = opts
r.ch = make(chan *entry.Entry, 1024)
r.stat.Name = "reader_" + strings.Replace(opts.Address, ":", "_", -1)
r.needDumpQueue = utils.NewUniqueQueue(100000) // cache 100000 keys
r.needRestoreChan = make(chan *needRestoreItem, 1024) // inflight 1024 keys
log.Infof("[%s] scanStandaloneReader init finished. dbs=[%v]", r.stat.Name, r.dbs)
return r
}