Chore: Update Redis library to v9 (#112115)

This commit is contained in:
Mariell Hoversholm
2025-10-14 10:36:53 +02:00
committed by GitHub
parent 99ea1defd6
commit 16502532e1
10 changed files with 45 additions and 46 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"strings"
"time"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/grafana/grafana/pkg/setting"
)
@@ -6,9 +6,9 @@ import (
"strings"
"testing"
"github.com/go-redis/redis/v8"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util/testutil"
"github.com/redis/go-redis/v9"
)
func TestIntegrationRedisCacheStorage(t *testing.T) {
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"testing"
"github.com/go-redis/redis/v8"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/assert"
)
+1 -1
View File
@@ -14,9 +14,9 @@ import (
"time"
"github.com/centrifugal/centrifuge"
"github.com/go-redis/redis/v8"
"github.com/gobwas/glob"
jsoniter "github.com/json-iterator/go"
"github.com/redis/go-redis/v9"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
+19 -24
View File
@@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"sync"
"time"
"github.com/go-redis/redis/v8"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/redis/go-redis/v9"
"github.com/grafana/grafana/pkg/services/live/orgchannel"
)
@@ -73,40 +74,34 @@ func (c *RedisFrameCache) Update(ctx context.Context, orgID int64, channel strin
key := c.getCacheKey(orgchannel.PrependOrgID(orgID, channel))
pipe := c.redisClient.TxPipeline()
defer func() { _ = pipe.Close() }()
pipe.HGetAll(ctx, key)
pipe.HMSet(ctx, key, map[string]string{
"schema": stringSchema,
"frame": string(jsonFrame.Bytes(data.IncludeAll)),
var mapReply *redis.MapStringStringCmd
replies, err := c.redisClient.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
mapReply = pipe.HGetAll(ctx, key)
pipe.HMSet(ctx, key, map[string]string{
"schema": stringSchema,
"frame": string(jsonFrame.Bytes(data.IncludeAll)),
})
pipe.Expire(ctx, key, frameCacheTTL)
return nil
})
pipe.Expire(ctx, key, frameCacheTTL)
replies, err := pipe.Exec(ctx)
if err != nil {
return false, err
}
if len(replies) == 0 {
return false, errors.New("no replies in response")
}
reply := replies[0]
if mapReply.Err() != nil {
return false, fmt.Errorf("error getting existing frame from redis: %w", mapReply.Err())
}
if reply.Err() != nil {
result, err := mapReply.Result()
if err != nil {
return false, err
}
if mapReply, ok := reply.(*redis.StringStringMapCmd); ok {
result, err := mapReply.Result()
if err != nil {
return false, err
}
if len(result) == 0 {
return true, nil
}
return result["schema"] != stringSchema, nil
if len(result) == 0 {
return true, nil
}
return true, nil
return result["schema"] != stringSchema, nil
}
func (c *RedisFrameCache) getCacheKey(channelID string) string {
@@ -1,13 +1,14 @@
package managedstream
import (
"context"
"os"
"strings"
"testing"
"github.com/go-redis/redis/v8"
"github.com/google/uuid"
"github.com/grafana/grafana/pkg/util/testutil"
"github.com/redis/go-redis/v9"
"github.com/stretchr/testify/require"
)
@@ -39,7 +40,7 @@ func TestIntegrationRedisCacheStorage(t *testing.T) {
require.NotNil(t, c)
testFrameCache(t, c)
keys, err := redisClient.Keys(redisClient.Context(), "*").Result()
keys, err := redisClient.Keys(t.Context(), "*").Result()
if err != nil {
require.NoError(t, err)
}
@@ -53,13 +54,18 @@ func TestIntegrationRedisCacheStorage(t *testing.T) {
func redisCleanup(t *testing.T, redisClient *redis.Client, prefix string) func() {
return func() {
keys, err := redisClient.Keys(redisClient.Context(), prefix+"*").Result()
ctx := t.Context()
ctx = context.WithoutCancel(ctx)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
keys, err := redisClient.Keys(ctx, prefix+"*").Result()
if err != nil {
require.NoError(t, err)
}
for _, key := range keys {
_, err := redisClient.Del(redisClient.Context(), key).Result()
_, err := redisClient.Del(ctx, key).Result()
require.NoError(t, err)
}
}