From 0980cd9a7249249672bc740c5631352ba55ac962 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Fri, 2 Feb 2024 17:24:05 +0600 Subject: [PATCH 1/3] chore(deps): bump github.com/alicebob/miniredis/v2 to v2.31.1 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 92e78567598f..3b12379c9ce5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/GoogleCloudPlatform/docker-credential-gcr v2.0.5+incompatible github.com/Masterminds/sprig/v3 v3.2.3 github.com/NYTimes/gziphandler v1.1.1 - github.com/alicebob/miniredis/v2 v2.31.0 + github.com/alicebob/miniredis/v2 v2.31.1 github.com/aquasecurity/bolt-fixtures v0.0.0-20200903104109-d34e7f983986 github.com/aquasecurity/defsec v0.94.1 github.com/aquasecurity/go-dep-parser v0.0.0-20240131191227-2779e24d07b5 diff --git a/go.sum b/go.sum index 4b177fb091c5..f8316c52a370 100644 --- a/go.sum +++ b/go.sum @@ -311,8 +311,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= -github.com/alicebob/miniredis/v2 v2.31.0 h1:ObEFUNlJwoIiyjxdrYF0QIDE7qXcLc7D3WpSH4c22PU= -github.com/alicebob/miniredis/v2 v2.31.0/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg= +github.com/alicebob/miniredis/v2 v2.31.1 h1:7XAt0uUg3DtwEKW5ZAGa+K7FZV2DdKQo5K/6TTnfX8Y= +github.com/alicebob/miniredis/v2 v2.31.1/go.mod h1:UB/T2Uztp7MlFSDakaX1sTXUv5CASoprx0wulRT6HBg= github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1rlcoLz8y5B2r4tTLMiVTrMtpfY0O8EScKJxaSaEc= github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= From 64a3d964ec33ff8f3d3deaadaee96d5d1934692a Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Fri, 2 Feb 2024 17:25:16 +0600 Subject: [PATCH 2/3] fix(redis): fix cursor usage in Clear function --- pkg/fanal/cache/redis.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/fanal/cache/redis.go b/pkg/fanal/cache/redis.go index 60096a1dc280..c2f0f4b6c1bb 100644 --- a/pkg/fanal/cache/redis.go +++ b/pkg/fanal/cache/redis.go @@ -131,18 +131,15 @@ func (c RedisCache) Close() error { func (c RedisCache) Clear() error { ctx := context.Background() - var cursor uint64 for { - var keys []string - var err error - keys, cursor, err = c.client.Scan(ctx, cursor, redisPrefix+"::*", 100).Result() + keys, cursor, err := c.client.Scan(ctx, 0, redisPrefix+"::*", 100).Result() if err != nil { return xerrors.Errorf("failed to perform prefix scanning: %w", err) } if err = c.client.Unlink(ctx, keys...).Err(); err != nil { return xerrors.Errorf("failed to unlink redis keys: %w", err) } - if cursor == 0 { + if cursor == 0 { // We clear all keys break } } From 0c82590d978f113858cd3acd6f97029765c2be22 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Fri, 2 Feb 2024 17:40:01 +0600 Subject: [PATCH 3/3] refactor: update comment --- pkg/fanal/cache/redis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/fanal/cache/redis.go b/pkg/fanal/cache/redis.go index c2f0f4b6c1bb..af9d2622b531 100644 --- a/pkg/fanal/cache/redis.go +++ b/pkg/fanal/cache/redis.go @@ -139,7 +139,7 @@ func (c RedisCache) Clear() error { if err = c.client.Unlink(ctx, keys...).Err(); err != nil { return xerrors.Errorf("failed to unlink redis keys: %w", err) } - if cursor == 0 { // We clear all keys + if cursor == 0 { // We cleared all keys break } }