Skip to content

Commit f1bcb0a

Browse files
author
Jamie Curnow
committed
Skip keys that no longer exist and don't exit
1 parent dcef1db commit f1bcb0a

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ go get github.com/jc21/redis-migrator
7070

7171
```bash
7272
git clone https://github.com/jc21/redis-migrator && cd redis-migrator
73-
go build -o bin/redis-migrator cmd/redis-migrator/main.go
73+
go build -v -ldflags="-X main.version=1.0.1" -o bin/redis-migrator cmd/redis-migrator/main.go
7474
./bin/redis-migrator -h
7575
```

cmd/redis-migrator/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
"redismigrator/pkg/migrator"
1111
)
1212

13+
var version string
14+
1315
func main() {
14-
argConfig := config.GetConfig()
16+
argConfig := config.GetConfig(&version)
1517
logger.Init(argConfig)
1618
logger.Trace("Args: %+v", argConfig)
1719

pkg/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
var appArguments model.ArgConfig
1111

1212
// GetConfig returns the ArgConfig
13-
func GetConfig() model.ArgConfig {
13+
func GetConfig(version *string) model.ArgConfig {
14+
model.SetVersion(version)
1415
config.FromEnv().To(&appArguments)
1516
arg.MustParse(&appArguments)
1617
return appArguments

pkg/migrator/migrate.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func DoMigration(sourceClient, destinationClient *redis.Client, keyFilter, keyPr
4141
}
4242

4343
counter := 0
44+
skipped := 0
4445
for _, sourceKey := range keys {
4546
destinationKey := keyPrefix + sourceKey
4647

@@ -58,15 +59,19 @@ func DoMigration(sourceClient, destinationClient *redis.Client, keyFilter, keyPr
5859
copyHash(sourceClient, destinationClient, sourceKey, destinationKey)
5960
case "list":
6061
copyList(sourceClient, destinationClient, sourceKey, destinationKey)
62+
case "none":
63+
// Key does not exist, or at least not anymore.
64+
skipped++
6165
default:
62-
logger.Error("Key type not yet sypported: %s", keyType)
66+
logger.Error("Key type not yet supported: %s", keyType)
67+
logger.Error("Migration was NOT completed!")
6368
os.Exit(1)
6469
}
6570

6671
counter++
6772
}
6873

69-
logger.Info("Migration completed with %d keys :)", counter)
74+
logger.Info("Migration completed with %d keys, %d skipped :)", counter, skipped)
7075
os.Exit(0)
7176
}
7277

pkg/model/arg_config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package model
22

33
import "fmt"
44

5+
var version *string
6+
57
// ArgConfig is the settings for passing arguments to the command
68
type ArgConfig struct {
79
SourceHost string `arg:"--source-host,required" help:"source redis server hostname"`
@@ -19,6 +21,16 @@ type ArgConfig struct {
1921
Verbose bool `arg:"-v" help:"Print a lot more info"`
2022
}
2123

24+
// SetVersion ...
25+
func SetVersion(ver *string) {
26+
version = ver
27+
}
28+
29+
// Version ...
30+
func (ArgConfig) Version() string {
31+
return fmt.Sprintf("v%s", *version)
32+
}
33+
2234
// Description returns a simple description of the command
2335
func (ArgConfig) Description() string {
2436
return `Redis Migrator will take the keys from one server/db and

0 commit comments

Comments
 (0)