Skip to content

Commit 0fd2c5d

Browse files
committed
make configuration items clearer
1 parent 99a1c80 commit 0fd2c5d

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
redis-shake is a tool for Redis data migration and data filtering.
88

9-
109
## Feature
1110

1211
* 🚄 High performance
@@ -16,7 +15,8 @@ redis-shake is a tool for Redis data migration and data filtering.
1615
* 💖 Support `restore` mode and `sync` mode
1716
* ☁️ Support Aliyun Redis and ElastiCache
1817

19-
For older versions of redis-shake (support codis, twemproxy) please visit [here](https://github.com/alibaba/RedisShake/tree/develop).
18+
For older versions of redis-shake (support codis, twemproxy) please
19+
visit [here](https://github.com/alibaba/RedisShake/tree/develop).
2020

2121
![redis-shake2.PNG](https://s2.loli.net/2022/07/10/OZrSGutknlI8XNp.png)
2222

@@ -42,7 +42,7 @@ sh build.sh
4242

4343
## Usage
4444

45-
1. Edit `redis-shake.toml` or `restore.toml` and modify the source and target configuration items in it.
45+
1. Edit `sync.toml` or `restore.toml`.
4646
2. Start redis-shake.
4747

4848
```shell
@@ -55,15 +55,15 @@ sh build.sh
5555

5656
## Configure
5757

58-
The redis-shake configuration file refers to `redis-shake.toml` or `restore.toml`.
58+
The redis-shake configuration file refers to `sync.toml` or `restore.toml`.
5959

6060
## Data filtering
6161

6262
redis-shake supports custom filtering rules using lua scripts. redis-shake can be started with
6363
the following command:
6464

6565
```shell
66-
./bin/redis-shake redis-shake.toml filter/xxx.lua
66+
./bin/redis-shake sync.toml filter/xxx.lua
6767
```
6868

6969
Some following filter templates are provided in `filter` directory:

build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ for g in "linux" "darwin"; do
2424
done
2525
done
2626

27-
cp redis-shake.toml "$BIN_DIR"
27+
cp sync.toml "$BIN_DIR"
2828
cp restore.toml "$BIN_DIR"
2929

3030
if [ "$1" == "dist" ]; then
3131
echo "[ DIST ]"
3232
cd bin
3333
cp -r ../filters ./
34-
tar -czvf ./redis-shake.tar.gz ./redis-shake.toml ./restore.toml ./redis-shake-* ./filters
34+
tar -czvf ./redis-shake.tar.gz ./sync.toml ./restore.toml ./redis-shake-* ./filters
3535
rm -rf ./filters
3636
cd ..
3737
fi

cmd/redis-shake/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ import (
1717

1818
func main() {
1919
if len(os.Args) < 2 || len(os.Args) > 3 {
20-
fmt.Println("Usage: redis-shake <config file> <lua file>")
21-
fmt.Println("Example: redis-shake config.toml lua.lua")
20+
fmt.Println("Usage: redis-shake <config file> <filter file>")
21+
fmt.Println("Example: redis-shake config.toml filter.lua")
2222
os.Exit(1)
2323
}
2424

25+
// load filter file
2526
if len(os.Args) == 3 {
2627
luaFile := os.Args[2]
2728
filter.LoadFromFile(luaFile)
@@ -40,6 +41,7 @@ func main() {
4041
log.Infof("No lua file specified, will not filter any cmd.")
4142
}
4243

44+
// start pprof
4345
if config.Config.Advanced.PprofPort != 0 {
4446
go func() {
4547
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", config.Config.Advanced.PprofPort), nil)
@@ -64,12 +66,12 @@ func main() {
6466
// create reader
6567
source := &config.Config.Source
6668
var theReader reader.Reader
67-
if source.Type == "sync" {
69+
if config.Config.Type == "sync" {
6870
theReader = reader.NewPSyncReader(source.Address, source.Username, source.Password, source.IsTLS, source.ElastiCachePSync)
69-
} else if source.Type == "restore" {
71+
} else if config.Config.Type == "restore" {
7072
theReader = reader.NewRDBReader(source.RDBFilePath)
7173
} else {
72-
log.Panicf("unknown source type: %s", source.Type)
74+
log.Panicf("unknown source type: %s", config.Config.Type)
7375
}
7476
ch := theReader.StartRead()
7577

internal/config/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
)
1111

1212
type tomlSource struct {
13-
Type string `toml:"type"`
13+
// sync mode
1414
Address string `toml:"address"`
1515
Username string `toml:"username"`
1616
Password string `toml:"password"`
1717
IsTLS bool `toml:"tls"`
1818
ElastiCachePSync string `toml:"elasticache_psync"`
19-
RDBFilePath string `toml:"rdb_file_path"`
19+
20+
// restore mode
21+
RDBFilePath string `toml:"rdb_file_path"`
2022
}
2123

2224
type tomlTarget struct {
@@ -49,6 +51,7 @@ type tomlAdvanced struct {
4951
}
5052

5153
type tomlShakeConfig struct {
54+
Type string
5255
Source tomlSource
5356
Target tomlTarget
5457
Advanced tomlAdvanced
@@ -57,8 +60,9 @@ type tomlShakeConfig struct {
5760
var Config tomlShakeConfig
5861

5962
func init() {
63+
Config.Type = "sync"
64+
6065
// source
61-
Config.Source.Type = "sync"
6266
Config.Source.Address = ""
6367
Config.Source.Username = ""
6468
Config.Source.Password = ""

restore.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
type = "restore"
2+
13
[source]
2-
type = "restore" # sync, restore
34
# Path to the dump.rdb file. Absolute path or relative path. Note
45
# that relative paths are relative to the dir directory.
56
rdb_file_path = "dump.rdb"

redis-shake.toml renamed to sync.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
type = "sync"
2+
13
[source]
2-
type = "sync" # sync or restore
34
address = "127.0.0.1:6379"
45
username = "" # keep empty if not using ACL
56
password = "" # keep empty if no authentication is required
67
tls = false
78
elasticache_psync = "" # using when source is ElastiCache. ref: https://github.com/alibaba/RedisShake/issues/373
89

910
[target]
10-
type = "standalone" # standalone or cluster
11+
type = "standalone" # "standalone" or "cluster"
1112
# When the target is a cluster, write the address of one of the nodes.
1213
# redis-shake will obtain other nodes through the `cluster nodes` command.
1314
address = "127.0.0.1:6380"

test/assets/empty.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
type = "sync"
2+
13
[source]
2-
type = "sync" # sync or restore
34
address = "127.0.0.1:6379"
45
username = "" # keep empty if not using ACL
56
password = "" # keep empty if no authentication is required

0 commit comments

Comments
 (0)