Skip to content

Commit 2900a21

Browse files
authored
fix: fix cursor usage in Redis Clear function (aquasecurity#6056)
1 parent 85cb9a7 commit 2900a21

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible
1212
github.com/Masterminds/sprig/v3 v3.2.3
1313
github.com/NYTimes/gziphandler v1.1.1
14-
github.com/alicebob/miniredis/v2 v2.31.0
14+
github.com/alicebob/miniredis/v2 v2.31.1
1515
github.com/aquasecurity/bolt-fixtures v0.0.0-20200903104109-d34e7f983986
1616
github.com/aquasecurity/defsec v0.94.1
1717
github.com/aquasecurity/go-dep-parser v0.0.0-20240202105001-4f19ab402b0b

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
311311
github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0=
312312
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
313313
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
314-
github.com/alicebob/miniredis/v2 v2.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpSH4c22PU=
315-
github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
314+
github.com/alicebob/miniredis/v2 v2.31.1 h1:7XAt0uUg3DtwEKW5ZAGa+K7FZV2DdKQo5K/6TTnfX8Y=
315+
github.com/alicebob/miniredis/v2 v2.31.1/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg=
316316
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1rlcoLz8y5B2r4tTLMiVTrMtpfY0O8EScKJxaSaEc=
317317
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
318318
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=

pkg/fanal/cache/redis.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,15 @@ func (c RedisCache) Close() error {
131131
func (c RedisCache) Clear() error {
132132
ctx := context.Background()
133133

134-
var cursor uint64
135134
for {
136-
var keys []string
137-
var err error
138-
keys, cursor, err = c.client.Scan(ctx, cursor, redisPrefix+"::*", 100).Result()
135+
keys, cursor, err := c.client.Scan(ctx, 0, redisPrefix+"::*", 100).Result()
139136
if err != nil {
140137
return xerrors.Errorf("failed to perform prefix scanning: %w", err)
141138
}
142139
if err = c.client.Unlink(ctx, keys...).Err(); err != nil {
143140
return xerrors.Errorf("failed to unlink redis keys: %w", err)
144141
}
145-
if cursor == 0 {
142+
if cursor == 0 { // We cleared all keys
146143
break
147144
}
148145
}

0 commit comments

Comments
 (0)