@@ -113,6 +113,18 @@ func newClient(url string, mode Mode) (redis.UniversalClient, error) {
113
113
}
114
114
115
115
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
+
116
128
return & Redis {
117
129
client : client ,
118
130
config : config ,
@@ -138,17 +150,7 @@ func (r *Redis) Open(url string) (database.Driver, error) {
138
150
return nil , err
139
151
}
140
152
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
152
154
rawLockTimeout := query .Get ("x-lock-timeout" )
153
155
if rawLockTimeout != "" {
154
156
lockTimeout , err = time .ParseDuration (rawLockTimeout )
@@ -165,8 +167,8 @@ func (r *Redis) Open(url string) (database.Driver, error) {
165
167
return WithInstance (
166
168
client ,
167
169
& Config {
168
- MigrationsKey : migrationsKey ,
169
- LockKey : lockKey ,
170
+ MigrationsKey : query . Get ( "x-migrations-key" ) ,
171
+ LockKey : query . Get ( "x-lock-key" ) ,
170
172
LockTimeout : lockTimeout ,
171
173
},
172
174
)
0 commit comments