support syncing lua in RDB

v4
vinllen 6 years ago
parent 46e6ccd3eb
commit cb3f410a47
  1. 5
      .gitignore
  2. 5
      ChangeLog
  3. 10
      src/pkg/rdb/loader.go
  4. 4
      src/pkg/rdb/reader.go
  5. 9
      src/redis-shake/common/utils.go

5
.gitignore vendored

@ -10,8 +10,13 @@ logs
*.yml
*.pid
*.tar.gz
*.log
tags
result.db.*
bin/*
!/bin/redis-shake.*
conf/*
!conf/redis-shake.conf
dump.data
runtime.trace

@ -1,6 +1,9 @@
2019-03-27 Alibaba Cloud.
* version: 1.2.1
* IMPROVE: support syncing lua script in RDB syncing.
2019-03-11 Alibaba Cloud.
* version: 1.2.0
* redis-shake: support 5.0.
* IMPROVE: support 5.0.
2019-02-21 Alibaba Cloud.
* version: 1.0.0
* redis-shake: initial release.

@ -121,10 +121,18 @@ func (l *Loader) NextBinEntry() (*BinEntry, error) {
t = rtype
}
switch t {
case rdbFlagAUX:
case RdbFlagAUX:
aux_key, _ := l.ReadString()
aux_value, _ := l.ReadString()
log.Info("Aux information key:", string(aux_key), " value:", string(aux_value))
if string(aux_key) == "lua" {
// we should handle the lua script
entry.DB = l.db
entry.Key = aux_key
entry.Type = t
entry.Value = aux_value
return entry, nil
}
case rdbFlagResizeDB:
db_size, _ := l.ReadLength()
expire_size, _ := l.ReadLength()

@ -36,7 +36,7 @@ const (
RDBTypeStreamListPacks = 15 // stream
rdbFlagOnlyValue = 0xf9
rdbFlagAUX = 0xfa
RdbFlagAUX = 0xfa
rdbFlagResizeDB = 0xfb
rdbFlagExpiryMS = 0xfc
rdbFlagExpiry = 0xfd
@ -98,7 +98,7 @@ func (r *rdbReader) readObjectValue(t byte, l *Loader) ([]byte, error) {
switch t {
default:
return nil, errors.Errorf("unknown object-type %02x", t)
case rdbFlagAUX:
case RdbFlagAUX:
fallthrough
case rdbFlagResizeDB:
fallthrough

@ -679,6 +679,15 @@ func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry) {
return
}
// 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())
}
return
}
// TODO, need to judge big key
if e.Type != rdb.RDBTypeStreamListPacks &&
(uint64(len(e.Value)) > conf.Options.BigKeyThreshold || e.RealMemberCount != 0) {

Loading…
Cancel
Save