From e861789bed82c09a8af656ecf4f34db13a922e50 Mon Sep 17 00:00:00 2001 From: vinllen Date: Mon, 24 Jun 2019 15:00:24 +0800 Subject: [PATCH] support lua filter --- conf/redis-shake.conf | 4 ++++ src/redis-shake/common/filter.go | 16 ++++++++++++++++ src/redis-shake/common/utils.go | 8 +++++--- src/redis-shake/configure/configure.go | 1 + src/redis-shake/sync.go | 2 +- 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/redis-shake/common/filter.go diff --git a/conf/redis-shake.conf b/conf/redis-shake.conf index d8c6f71..8acf1a7 100644 --- a/conf/redis-shake.conf +++ b/conf/redis-shake.conf @@ -119,6 +119,10 @@ filter.key = # used in `sync`. # 指定过滤slot,只让指定的slot通过 filter.slot = +# filter lua script. true means not pass. However, in redis 5.0, the lua +# converts to transaction(multi+{commands}+exec) which will be passed. +# 控制不让lua脚本通过,true表示不通过 +filter.lua = false # big key threshold, the default is 500 * 1024 * 1024 bytes. If the value is bigger than # this given value, all the field will be spilt and write into the target in order. diff --git a/src/redis-shake/common/filter.go b/src/redis-shake/common/filter.go new file mode 100644 index 0000000..a4a1adc --- /dev/null +++ b/src/redis-shake/common/filter.go @@ -0,0 +1,16 @@ +package utils + +import "strings" + +// return true means not pass +func FilterCommands(cmd string, luaFilter bool) bool { + if strings.EqualFold(cmd, "opinfo") { + return true + } + + if luaFilter && (strings.EqualFold(cmd, "eval") || strings.EqualFold(cmd, "script")) { + return true + } + + return false +} \ No newline at end of file diff --git a/src/redis-shake/common/utils.go b/src/redis-shake/common/utils.go index 8314cd5..5623ac9 100644 --- a/src/redis-shake/common/utils.go +++ b/src/redis-shake/common/utils.go @@ -733,9 +733,11 @@ func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry) { // load lua script if e.Type == rdb.RdbFlagAUX && string(e.Key) == "lua" { - _, err := c.Do("script", "load", e.Value) - if err != nil { - log.Panicf(err.Error()) + if conf.Options.FilterLua == false { + _, err := c.Do("script", "load", e.Value) + if err != nil { + log.Panicf(err.Error()) + } } return } diff --git a/src/redis-shake/configure/configure.go b/src/redis-shake/configure/configure.go index 6676231..3ffc31d 100644 --- a/src/redis-shake/configure/configure.go +++ b/src/redis-shake/configure/configure.go @@ -36,6 +36,7 @@ type Configuration struct { FilterDB string `config:"filter.db"` FilterKey []string `config:"filter.key"` FilterSlot []string `config:"filter.slot"` + FilterLua bool `config:"filter.lua"` BigKeyThreshold uint64 `config:"big_key_threshold"` Psync bool `config:"psync"` Metric bool `config:"metric"` diff --git a/src/redis-shake/sync.go b/src/redis-shake/sync.go index f53a83c..1da67a1 100644 --- a/src/redis-shake/sync.go +++ b/src/redis-shake/sync.go @@ -613,7 +613,7 @@ func (ds *dbSyncer) syncCommand(reader *bufio.Reader, target []string, auth_type } bypass = !base.AcceptDB(uint32(n)) isselect = true - } else if strings.EqualFold(scmd, "opinfo") { + } else if utils.FilterCommands(scmd, conf.Options.FilterLua) { ignorecmd = true } if bypass || ignorecmd {