support lua filter

v4
vinllen 6 years ago
parent 62d2f9890b
commit e861789bed
  1. 4
      conf/redis-shake.conf
  2. 16
      src/redis-shake/common/filter.go
  3. 8
      src/redis-shake/common/utils.go
  4. 1
      src/redis-shake/configure/configure.go
  5. 2
      src/redis-shake/sync.go

@ -119,6 +119,10 @@ filter.key =
# used in `sync`. # used in `sync`.
# 指定过滤slot,只让指定的slot通过 # 指定过滤slot,只让指定的slot通过
filter.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 # 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. # this given value, all the field will be spilt and write into the target in order.

@ -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
}

@ -733,9 +733,11 @@ func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry) {
// load lua script // load lua script
if e.Type == rdb.RdbFlagAUX && string(e.Key) == "lua" { if e.Type == rdb.RdbFlagAUX && string(e.Key) == "lua" {
_, err := c.Do("script", "load", e.Value) if conf.Options.FilterLua == false {
if err != nil { _, err := c.Do("script", "load", e.Value)
log.Panicf(err.Error()) if err != nil {
log.Panicf(err.Error())
}
} }
return return
} }

@ -36,6 +36,7 @@ type Configuration struct {
FilterDB string `config:"filter.db"` FilterDB string `config:"filter.db"`
FilterKey []string `config:"filter.key"` FilterKey []string `config:"filter.key"`
FilterSlot []string `config:"filter.slot"` FilterSlot []string `config:"filter.slot"`
FilterLua bool `config:"filter.lua"`
BigKeyThreshold uint64 `config:"big_key_threshold"` BigKeyThreshold uint64 `config:"big_key_threshold"`
Psync bool `config:"psync"` Psync bool `config:"psync"`
Metric bool `config:"metric"` Metric bool `config:"metric"`

@ -613,7 +613,7 @@ func (ds *dbSyncer) syncCommand(reader *bufio.Reader, target []string, auth_type
} }
bypass = !base.AcceptDB(uint32(n)) bypass = !base.AcceptDB(uint32(n))
isselect = true isselect = true
} else if strings.EqualFold(scmd, "opinfo") { } else if utils.FilterCommands(scmd, conf.Options.FilterLua) {
ignorecmd = true ignorecmd = true
} }
if bypass || ignorecmd { if bypass || ignorecmd {

Loading…
Cancel
Save