SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
perf(cache): should delete multiple keys at once to reduce operations in Redis cache (#6170)
hulk291b3ba357a9
diff --git a/pkg/query-service/cache/redis/redis.go b/pkg/query-service/cache/redis/redis.goindex 6338eca6f3..737fa66d06 100644--- a/pkg/query-service/cache/redis/redis.go+++ b/pkg/query-service/cache/redis/redis.go@@ -2,6 +2,7 @@ package redisimport ("context"+ "errors""fmt""time"@@ -47,7 +48,7 @@ func (c *cache) Store(cacheKey string, data []byte, ttl time.Duration) error {func (c *cache) Retrieve(cacheKey string, allowExpired bool) ([]byte, status.RetrieveStatus, error) {data, err := c.client.Get(context.Background(), cacheKey).Bytes()if err != nil {- if err == redis.Nil {+ if errors.Is(err, redis.Nil) {return nil, status.RetrieveStatusKeyMiss, nil}return nil, status.RetrieveStatusError, err@@ -65,16 +66,13 @@ func (c *cache) SetTTL(cacheKey string, ttl time.Duration) {// Remove removes the cache entryfunc (c *cache) Remove(cacheKey string) {- err := c.client.Del(context.Background(), cacheKey).Err()- if err != nil {- zap.L().Error("error deleting cache key", zap.String("cacheKey", cacheKey), zap.Error(err))- }+ c.BulkRemove([]string{cacheKey})}// BulkRemove removes the cache entriesfunc (c *cache) BulkRemove(cacheKeys []string) {- for _, cacheKey := range cacheKeys {- c.Remove(cacheKey)+ if err := c.client.Del(context.Background(), cacheKeys...).Err(); err != nil {+ zap.L().Error("error deleting cache keys", zap.Strings("cacheKeys", cacheKeys), zap.Error(err))}}diff --git a/pkg/query-service/cache/redis/redis_test.go b/pkg/query-service/cache/redis/redis_test.goindex 41d96836c8..baed3416a3 100644--- a/pkg/query-service/cache/redis/redis_test.go+++ b/pkg/query-service/cache/redis/redis_test.go@@ -82,8 +82,7 @@ func TestBulkRemove(t *testing.T) {mock.ExpectSet("key2", []byte("value2"), 10*time.Second).RedisNil()c.Store("key2", []byte("value2"), 10*time.Second)- mock.ExpectDel("key").RedisNil()- mock.ExpectDel("key2").RedisNil()+ mock.ExpectDel("key", "key2").RedisNil()c.BulkRemove([]string{"key", "key2"})if err := mock.ExpectationsWereMet(); err != nil {