diff --git a/storage/redis.go b/storage/redis.go index b49cbc2fc..483c58e6b 100644 --- a/storage/redis.go +++ b/storage/redis.go @@ -169,6 +169,7 @@ func NewRedisClusterPool(forceReconnect bool, config *RedisStorageConfig) *Redis redisClusterSingleton = &RedisManager{} redisClusterSingleton.kv = kv redisClusterSingleton.list = l + redisClusterSingleton.conn = conn return redisClusterSingleton } diff --git a/storage/redis_test.go b/storage/redis_test.go index 7628c7e5b..04ed1fc74 100644 --- a/storage/redis_test.go +++ b/storage/redis_test.go @@ -5,6 +5,9 @@ import ( "fmt" "testing" "time" + + "github.com/TykTechnologies/storage/temporal/model" + "github.com/stretchr/testify/assert" ) func TestRedisAddressConfiguration(t *testing.T) { @@ -139,3 +142,33 @@ func TestRedisClusterStorageManager_GetAndDeleteSet(t *testing.T) { }) } } + +func TestNewRedisClusterPool(t *testing.T) { + tcs := []struct { + name string + cfg *RedisStorageConfig + }{ + { + name: "connect to localhost:6379", + cfg: &RedisStorageConfig{ + Host: "localhost", + Port: 6379, + }, + }, + } + + for _, tc := range tcs { + t.Run(tc.name, func(t *testing.T) { + pool := NewRedisClusterPool(false, tc.cfg) + if pool == nil { + t.Fatal("pool is nil") + } + + assert.NotNil(t, pool.conn) + assert.NotNil(t, pool.kv) + assert.NotNil(t, pool.list) + assert.Equal(t, pool.conn.Type(), model.RedisV9Type) + assert.NoError(t, pool.conn.Ping(context.Background())) + }) + } +}