fix(redis): support custom connection config #5376
Draft
+202
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support configurable Redis connection settings
Description
This PR introduces support for configuring
MaxRetries,MinIdleConns,DB, andPoolSizein Redis connections viaRedisConf.Previously, these values were hardcoded:
MaxRetries: 3MinIdleConns: 8Changes
core/stores/redis/conf.go: AddedMaxRetries(default: 3),MinIdleConns(default: 8),DB(default: 0), andPoolSize(optional, defaults to dynamic calculation if 0) to theRedisConfstruct.core/stores/redis/redis.go:Redisstruct to hold these options.NewRedisandnewRedisto accept and apply these options.WithMaxRetries,WithMinIdleConns,WithDB, andWithPoolSizeoptions.core/stores/redis/redisclientmanager.go: UpdatedgetClientto initialize thego-redisclient with the configured values.core/stores/redis/redisclustermanager.go: UpdatedgetClusterto initialize thego-rediscluster client with the configured values.core/stores/redis/redisblockingnode.go: UpdatedCreateBlockingNodeto respectMaxRetries(while keeping pool size min/max at 1 for blocking operations).Verification / Test Plan
A new test case
TestRedisOptionshas been added tocore/stores/redis/redis_test.gocovering:MaxRetriesto -1).To run the specific test:
go test -v ./core/stores/redis/ -run TestRedisOptionsTo run all Redis tests:
go test -v ./core/stores/redis/...Related Issue
Fixes #4668
How to Test
Unit Tests:
Run the newly added unit tests to verify configuration propagation:
go test -v core/stores/redis/redis_test.go -run TestRedisOptionsManual Verification:
You can verify the configuration by initializing a Redis client with custom values: