-
Notifications
You must be signed in to change notification settings - Fork 692
chore(deps): replace stale dependency github.com/go-redis/redis/v8 #7010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import ( | |
| "time" | ||
| "unsafe" | ||
|
|
||
| "github.com/go-redis/redis/v8" | ||
| "github.com/redis/go-redis/v9" | ||
|
|
||
| "github.com/grafana/dskit/flagext" | ||
| ) | ||
|
|
@@ -55,6 +55,7 @@ type RedisClient struct { | |
| expiration time.Duration | ||
| timeout time.Duration | ||
| rdb redis.UniversalClient | ||
| isCluster bool | ||
| } | ||
|
|
||
| // NewRedisClient creates Redis client | ||
|
|
@@ -68,16 +69,19 @@ func NewRedisClient(cfg *RedisConfig) *RedisClient { | |
| SentinelPassword: cfg.SentinelPassword.String(), | ||
| DB: cfg.DB, | ||
| PoolSize: cfg.PoolSize, | ||
| IdleTimeout: cfg.IdleTimeout, | ||
| MaxConnAge: cfg.MaxConnAge, | ||
| ConnMaxIdleTime: cfg.IdleTimeout, | ||
| ConnMaxLifetime: cfg.MaxConnAge, | ||
| } | ||
| if cfg.EnableTLS { | ||
| opt.TLSConfig = &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify} | ||
| } | ||
| rdb := redis.NewUniversalClient(opt) | ||
| _, isCluster := rdb.(*redis.ClusterClient) | ||
| return &RedisClient{ | ||
| expiration: cfg.Expiration, | ||
| timeout: cfg.Timeout, | ||
| rdb: redis.NewUniversalClient(opt), | ||
| rdb: rdb, | ||
| isCluster: isCluster, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -109,7 +113,14 @@ func (c *RedisClient) MSet(ctx context.Context, keys []string, values [][]byte) | |
| return fmt.Errorf("MSet the length of keys and values not equal, len(keys)=%d, len(values)=%d", len(keys), len(values)) | ||
| } | ||
|
|
||
| pipe := c.rdb.TxPipeline() | ||
| // In cluster mode, cross-slot transactions are not supported. Use a non-transactional | ||
| // pipeline to allow keys on different slots, consistent with how MGet handles clusters. | ||
| var pipe redis.Pipeliner | ||
| if c.isCluster { | ||
| pipe = c.rdb.Pipeline() | ||
| } else { | ||
| pipe = c.rdb.TxPipeline() | ||
| } | ||
|
Comment on lines
+116
to
+123
|
||
| for i := range keys { | ||
| pipe.Set(ctx, keys[i], values[i], c.expiration) | ||
| } | ||
|
|
@@ -129,9 +140,7 @@ func (c *RedisClient) MGet(ctx context.Context, keys []string) ([][]byte, error) | |
| // redis.UniversalClient can take redis.Client and redis.ClusterClient. | ||
| // if redis.Client is set, then Single node or sentinel configuration. mget is always supported. | ||
| // if redis.ClusterClient is set, then Redis Cluster configuration. mget may not be supported. | ||
| _, isCluster := c.rdb.(*redis.ClusterClient) | ||
|
|
||
| if isCluster { | ||
| if c.isCluster { | ||
| for i, key := range keys { | ||
| cmd := c.rdb.Get(ctx, key) | ||
| err := cmd.Err() | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HIGH: This changes
MSetsemantics in cluster mode from (per-node) transactional to non-transactional, which can lead to partial writes if someSETs fail. If callers rely onMSetbeing all-or-nothing, consider either (a) documenting explicitly that cluster-modeMSetis best-effort/non-atomic, or (b) preserving atomicity when possible (e.g., if all keys map to the same hash slot, use a transaction; otherwise fall back to non-transactional pipeline).