Skip to content

Commit 1ad4f4f

Browse files
committed
Fix WithInstance Config defaults
1 parent ccae5e1 commit 1ad4f4f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

database/redis/redis.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ func newClient(url string, mode Mode) (redis.UniversalClient, error) {
113113
}
114114

115115
func WithInstance(client redis.UniversalClient, config *Config) (database.Driver, error) {
116+
if config.MigrationsKey == "" {
117+
config.MigrationsKey = DefaultMigrationsKey
118+
}
119+
120+
if config.LockKey == "" {
121+
config.LockKey = DefaultLockKey
122+
}
123+
124+
if config.LockTimeout == 0 {
125+
config.LockTimeout = DefaultLockTimeout
126+
}
127+
116128
return &Redis{
117129
client: client,
118130
config: config,
@@ -138,17 +150,7 @@ func (r *Redis) Open(url string) (database.Driver, error) {
138150
return nil, err
139151
}
140152

141-
migrationsKey := query.Get("x-migrations-key")
142-
if migrationsKey == "" {
143-
migrationsKey = DefaultMigrationsKey
144-
}
145-
146-
lockKey := query.Get("x-lock-key")
147-
if lockKey == "" {
148-
lockKey = DefaultLockKey
149-
}
150-
151-
lockTimeout := DefaultLockTimeout
153+
var lockTimeout time.Duration
152154
rawLockTimeout := query.Get("x-lock-timeout")
153155
if rawLockTimeout != "" {
154156
lockTimeout, err = time.ParseDuration(rawLockTimeout)
@@ -165,8 +167,8 @@ func (r *Redis) Open(url string) (database.Driver, error) {
165167
return WithInstance(
166168
client,
167169
&Config{
168-
MigrationsKey: migrationsKey,
169-
LockKey: lockKey,
170+
MigrationsKey: query.Get("x-migrations-key"),
171+
LockKey: query.Get("x-lock-key"),
170172
LockTimeout: lockTimeout,
171173
},
172174
)

0 commit comments

Comments
 (0)