Skip to content

Commit

Permalink
添加scan时候的一次扫描次数控制配置,防止源端cpu高
Browse files Browse the repository at this point in the history
  • Loading branch information
blight19 committed Mar 20, 2024
1 parent 36915f0 commit f286da4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/client/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ func (r *Redis) Close() {

/* Commands */

func (r *Redis) Scan(cursor uint64) (newCursor uint64, keys []string) {
r.Send("scan", strconv.FormatUint(cursor, 10), "count", "2048")
func (r *Redis) Scan(cursor uint64, batch string) (newCursor uint64, keys []string) {
r.Send("scan", strconv.FormatUint(cursor, 10), "count", batch)
reply, err := r.Receive()
if err != nil {
log.Panicf(err.Error())
Expand Down
4 changes: 3 additions & 1 deletion internal/reader/scan_standalone_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ScanReaderOptions struct {
KSN bool `mapstructure:"ksn" default:"false"`
DBS []int `mapstructure:"dbs"`
PreferReplica bool `mapstructure:"prefer_replica" default:"false"`
Batch int `mapstructure:"batch" default:"2048"`
}

type dbKey struct {
Expand Down Expand Up @@ -131,9 +132,10 @@ func (r *scanStandaloneReader) scan() {
}

var cursor uint64 = 0
batch := strconv.Itoa(r.opts.Batch)
for {
var keys []string
cursor, keys = c.Scan(cursor)
cursor, keys = c.Scan(cursor, batch)
for _, key := range keys {
r.keyQueue.Put(dbKey{dbId, key}) // pass value not pointer
}
Expand Down

0 comments on commit f286da4

Please sign in to comment.