Skip to content

Commit

Permalink
make configuration items clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
suxb201 committed Sep 22, 2022
1 parent 99a1c80 commit 0fd2c5d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

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


## Feature

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

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

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

Expand All @@ -42,7 +42,7 @@ sh build.sh

## Usage

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

```shell
Expand All @@ -55,15 +55,15 @@ sh build.sh

## Configure

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

## Data filtering

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

```shell
./bin/redis-shake redis-shake.toml filter/xxx.lua
./bin/redis-shake sync.toml filter/xxx.lua
```

Some following filter templates are provided in `filter` directory:
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ for g in "linux" "darwin"; do
done
done

cp redis-shake.toml "$BIN_DIR"
cp sync.toml "$BIN_DIR"
cp restore.toml "$BIN_DIR"

if [ "$1" == "dist" ]; then
echo "[ DIST ]"
cd bin
cp -r ../filters ./
tar -czvf ./redis-shake.tar.gz ./redis-shake.toml ./restore.toml ./redis-shake-* ./filters
tar -czvf ./redis-shake.tar.gz ./sync.toml ./restore.toml ./redis-shake-* ./filters
rm -rf ./filters
cd ..
fi
12 changes: 7 additions & 5 deletions cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (

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

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

// start pprof
if config.Config.Advanced.PprofPort != 0 {
go func() {
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", config.Config.Advanced.PprofPort), nil)
Expand All @@ -64,12 +66,12 @@ func main() {
// create reader
source := &config.Config.Source
var theReader reader.Reader
if source.Type == "sync" {
if config.Config.Type == "sync" {
theReader = reader.NewPSyncReader(source.Address, source.Username, source.Password, source.IsTLS, source.ElastiCachePSync)
} else if source.Type == "restore" {
} else if config.Config.Type == "restore" {
theReader = reader.NewRDBReader(source.RDBFilePath)
} else {
log.Panicf("unknown source type: %s", source.Type)
log.Panicf("unknown source type: %s", config.Config.Type)
}
ch := theReader.StartRead()

Expand Down
10 changes: 7 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
)

type tomlSource struct {
Type string `toml:"type"`
// sync mode
Address string `toml:"address"`
Username string `toml:"username"`
Password string `toml:"password"`
IsTLS bool `toml:"tls"`
ElastiCachePSync string `toml:"elasticache_psync"`
RDBFilePath string `toml:"rdb_file_path"`

// restore mode
RDBFilePath string `toml:"rdb_file_path"`
}

type tomlTarget struct {
Expand Down Expand Up @@ -49,6 +51,7 @@ type tomlAdvanced struct {
}

type tomlShakeConfig struct {
Type string
Source tomlSource
Target tomlTarget
Advanced tomlAdvanced
Expand All @@ -57,8 +60,9 @@ type tomlShakeConfig struct {
var Config tomlShakeConfig

func init() {
Config.Type = "sync"

// source
Config.Source.Type = "sync"
Config.Source.Address = ""
Config.Source.Username = ""
Config.Source.Password = ""
Expand Down
3 changes: 2 additions & 1 deletion restore.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type = "restore"

[source]
type = "restore" # sync, restore
# Path to the dump.rdb file. Absolute path or relative path. Note
# that relative paths are relative to the dir directory.
rdb_file_path = "dump.rdb"
Expand Down
5 changes: 3 additions & 2 deletions redis-shake.toml → sync.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
type = "sync"

[source]
type = "sync" # sync or restore
address = "127.0.0.1:6379"
username = "" # keep empty if not using ACL
password = "" # keep empty if no authentication is required
tls = false
elasticache_psync = "" # using when source is ElastiCache. ref: https://github.com/alibaba/RedisShake/issues/373

[target]
type = "standalone" # standalone or cluster
type = "standalone" # "standalone" or "cluster"
# When the target is a cluster, write the address of one of the nodes.
# redis-shake will obtain other nodes through the `cluster nodes` command.
address = "127.0.0.1:6380"
Expand Down
3 changes: 2 additions & 1 deletion test/assets/empty.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type = "sync"

[source]
type = "sync" # sync or restore
address = "127.0.0.1:6379"
username = "" # keep empty if not using ACL
password = "" # keep empty if no authentication is required
Expand Down

0 comments on commit 0fd2c5d

Please sign in to comment.