diff --git a/README.md b/README.md index 38d828d1..592f0640 100644 --- a/README.md +++ b/README.md @@ -173,9 +173,9 @@ server_id=1 # 配置 MySQL replaction 需要定义,不要和 go-mysql-transfer # 更新日志 -**v1.0.0 bate** +**v1.0.0 beta** -* 9.17 初始化提交bate版本 +* 9.17 初始化提交beta版本 **v1.0.1 release** diff --git a/service/endpoint/redis.go b/service/endpoint/redis.go index 59856446..04977880 100644 --- a/service/endpoint/redis.go +++ b/service/endpoint/redis.go @@ -22,6 +22,7 @@ import ( "log" "strings" "sync" + "time" "github.com/go-redis/redis" "github.com/pingcap/errors" @@ -265,6 +266,12 @@ func (s *RedisEndpoint) preparePipe(resp *model.RedisRespond, pipe redis.Cmdable val := redis.Z{Score: resp.Score, Member: resp.Val} pipe.ZAdd(resp.Key, val) } + default: + if resp.Action == "expire" { + vv, _ := resp.Val.(float64) + var s int64 = int64(vv) * 1000000000 //trans to ns + pipe.Expire(resp.Key, time.Duration(s)) + } } } diff --git a/service/luaengine/redis_actuator.go b/service/luaengine/redis_actuator.go index a59ce819..ed7665e8 100644 --- a/service/luaengine/redis_actuator.go +++ b/service/luaengine/redis_actuator.go @@ -19,7 +19,7 @@ package luaengine import ( "github.com/siddontang/go-mysql/canal" - "github.com/yuin/gopher-lua" + lua "github.com/yuin/gopher-lua" "go-mysql-transfer/global" "go-mysql-transfer/model" @@ -54,6 +54,8 @@ var _redisModuleApi = map[string]lua.LGFunction{ "ZADD": redisZAdd, "ZREM": redisZRem, + + "EXPIRE": redisExpire, } func rawOldRow(L *lua.LState) int { @@ -62,6 +64,14 @@ func rawOldRow(L *lua.LState) int { return 1 } +func redisExpire(L *lua.LState) int { + key := L.CheckString(1) + val := L.CheckAny(2) + ret := L.GetGlobal(_globalRET) + L.SetTable(ret, lua.LString("expire_0_"+key), val) + return 0 +} + func redisSet(L *lua.LState) int { key := L.CheckString(1) val := L.CheckAny(2) @@ -224,6 +234,12 @@ func DoRedisOps(input map[string]interface{}, previous map[string]interface{}, a ls = append(ls, resp) }) + var lsLen = len(ls) + if lsLen > 1 && ls[0].Action == "expire" { + // "expire" it will not work when the key not exist, swap it + ls[0], ls[lsLen-1] = ls[lsLen-1], ls[0] + } + return ls, nil }