Skip to content

Commit c7f0332

Browse files
authored
Refactor Redis config to use redis.Options struct
Simplified Redis configuration by consolidating individual parameters (address, password, and DB) into the redis.Options struct. This improves code readability, reduces redundancy, and aligns with the Redis client API's recommended usage. Signed-off-by: Tyler Lisowski <[email protected]>
1 parent aecde47 commit c7f0332

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

pkg/kv-cache/kvblock-indexer.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,15 @@ var _ KVBlockIndexer = &RedisKVBlockIndexer{}
5959

6060
// RedisKVBlockIndexerConfig holds the configuration for the RedisKVBlockIndexer.
6161
type RedisKVBlockIndexerConfig struct {
62-
RedisAddr string
63-
RedisPassword string
64-
RedisDB int
62+
RedisOpt *redis.Options
6563
}
6664

6765
func defaultRedisKVBlockIndexerConfig() *RedisKVBlockIndexerConfig {
6866
return &RedisKVBlockIndexerConfig{
69-
RedisAddr: "localhost:6379",
70-
RedisPassword: "",
71-
RedisDB: 0,
67+
RedisOpt: &redis.Options{
68+
Addr: "localhost:6379",
69+
DB: 0,
70+
},
7271
}
7372
}
7473

@@ -83,11 +82,7 @@ func NewRedisKVBlockIndexer(config *KVBlockIndexerConfig) (KVBlockIndexer, error
8382
config = DefaultKVBlockIndexerConfig()
8483
}
8584

86-
redisClient := redis.NewClient(&redis.Options{
87-
Addr: config.RedisAddr,
88-
Password: config.RedisPassword,
89-
DB: config.RedisDB,
90-
})
85+
redisClient := redis.NewClient(config.RedisOpt)
9186

9287
_, err := redisClient.Ping(context.Background()).Result()
9388
if err != nil {

tests/e2e/redis_mock/e2e_suite_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ func (s *KVCacheSuite) SetupTest() {
5959
s.Require().NoError(err)
6060

6161
s.config = kvcache.NewDefaultConfig()
62-
s.config.KVBlockIndexerConfig.RedisAddr = s.server.Addr()
62+
s.config.KVBlockIndexerConfig.RedisOpt = &redis.Options{
63+
Addr: s.server.Addr(),
64+
}
6365
s.config.PrefixStoreConfig.BlockSize = 4
6466
s.config.TokenProcessorConfig.ChunkSize = 4
6567

0 commit comments

Comments
 (0)