@@ -12,6 +12,8 @@ import (
12
12
radix "github.com/mediocregopher/radix/v3"
13
13
)
14
14
15
+ var AllDBs * uint8 = nil
16
+
15
17
func ttlToRedisCmd (k string , val int64 ) []string {
16
18
return []string {"EXPIREAT" , k , fmt .Sprint (time .Now ().Unix () + val )}
17
19
}
@@ -379,14 +381,21 @@ func DumpDB(client radix.Client, db *uint8, filter string, nWorkers int, withTTL
379
381
return nil
380
382
}
381
383
384
+ type Host struct {
385
+ Host string
386
+ Port int
387
+ Password string
388
+ TlsHandler * TlsHandler
389
+ }
390
+
382
391
// DumpServer dumps all Keys from the redis server given by redisURL,
383
392
// to the Logger logger. Progress notification informations
384
393
// are regularly sent to the channel progressNotifications
385
- func DumpServer (redisHost string , redisPort int , redisPassword string , db * uint8 , tlsHandler * TlsHandler , filter string , nWorkers int , withTTL bool , batchSize int , noscan bool , logger * log.Logger , serializer func ([]string ) string , progress chan <- ProgressNotification ) error {
386
- redisURL := RedisURL (redisHost , fmt .Sprint (redisPort ))
394
+ func DumpServer (s Host , db * uint8 , filter string , nWorkers int , withTTL bool , batchSize int , noscan bool , logger * log.Logger , serializer func ([]string ) string , progress chan <- ProgressNotification ) error {
395
+ redisURL := RedisURL (s . Host , fmt .Sprint (s . Port ))
387
396
getConnFunc := func (db * uint8 ) func (network , addr string ) (radix.Conn , error ) {
388
397
return func (network , addr string ) (radix.Conn , error ) {
389
- dialOpts , err := redisDialOpts (redisPassword , tlsHandler , db )
398
+ dialOpts , err := redisDialOpts (s . Password , s . TlsHandler , db )
390
399
if err != nil {
391
400
return nil , err
392
401
}
@@ -396,7 +405,7 @@ func DumpServer(redisHost string, redisPort int, redisPassword string, db *uint8
396
405
}
397
406
398
407
dbs := []uint8 {}
399
- if db != nil {
408
+ if db != AllDBs {
400
409
dbs = []uint8 {* db }
401
410
} else {
402
411
client , err := radix .NewPool ("tcp" , redisURL , nWorkers , radix .PoolConnFunc (getConnFunc (nil )))
@@ -416,6 +425,8 @@ func DumpServer(redisHost string, redisPort int, redisPassword string, db *uint8
416
425
if err != nil {
417
426
return err
418
427
}
428
+ defer client .Close ()
429
+
419
430
if err = DumpDB (client , & db , filter , nWorkers , withTTL , batchSize , noscan , logger , serializer , progress ); err != nil {
420
431
return err
421
432
}
0 commit comments