[Feature](database): Add Support for SSL Connections and Database URL Configuration (#2540)
* feat(database): add support for SSL connections and database URL configuration * feat(config): update Redis configuration to use TLS in configurre name instead of SSL * fix(database): remove default values for DatabaseURL and SSLMode in DatabaseConfig * chore(.gitignore): add cloudreve built binary to ignore list
This commit is contained in:
18
pkg/cache/redis.go
vendored
18
pkg/cache/redis.go
vendored
@@ -3,10 +3,12 @@ package cache
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/conf"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/logging"
|
||||
|
||||
"github.com/gomodule/redigo/redis"
|
||||
)
|
||||
|
||||
@@ -44,7 +46,7 @@ func deserializer(value []byte) (any, error) {
|
||||
}
|
||||
|
||||
// NewRedisStore 创建新的redis存储
|
||||
func NewRedisStore(l logging.Logger, size int, network, address, user, password, database string) *RedisStore {
|
||||
func NewRedisStore(l logging.Logger, size int, redisConfig *conf.Redis) *RedisStore {
|
||||
return &RedisStore{
|
||||
pool: &redis.Pool{
|
||||
MaxIdle: size,
|
||||
@@ -54,17 +56,19 @@ func NewRedisStore(l logging.Logger, size int, network, address, user, password,
|
||||
return err
|
||||
},
|
||||
Dial: func() (redis.Conn, error) {
|
||||
db, err := strconv.Atoi(database)
|
||||
db, err := strconv.Atoi(redisConfig.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err := redis.Dial(
|
||||
network,
|
||||
address,
|
||||
redisConfig.Network,
|
||||
redisConfig.Server,
|
||||
redis.DialDatabase(db),
|
||||
redis.DialPassword(password),
|
||||
redis.DialUsername(user),
|
||||
redis.DialPassword(redisConfig.Password),
|
||||
redis.DialUsername(redisConfig.User),
|
||||
redis.DialUseTLS(redisConfig.UseTLS),
|
||||
redis.DialTLSSkipVerify(redisConfig.TLSSkipVerify),
|
||||
)
|
||||
if err != nil {
|
||||
l.Panic("Failed to create Redis connection: %s", err)
|
||||
|
||||
Reference in New Issue
Block a user