|
@@ -106,6 +106,8 @@ func ListenMysql() {
|
|
|
binlogHandler.SetBinlogFileName(fileName, position)
|
|
|
c.SetEventHandler(binlogHandler)
|
|
|
//c.Run()
|
|
|
+ // 同步到redis
|
|
|
+ go binlogHandler.SyncToRedis()
|
|
|
|
|
|
pos := mysql.Position{
|
|
|
Name: fileName,
|
|
@@ -158,21 +160,15 @@ func getBinlogNamePosition() (fileName string, position uint32, err error) {
|
|
|
}
|
|
|
|
|
|
// 从mysql中获取最新的binlog文件名称和位置,名称不一致则以mysql中为准
|
|
|
- item, tmpErr := binlog.GetShowMaster()
|
|
|
- if tmpErr != nil {
|
|
|
- err = tmpErr
|
|
|
- return
|
|
|
- }
|
|
|
- dbFileName := item.File
|
|
|
- dbPosition := item.Position
|
|
|
- if fileName != dbFileName {
|
|
|
- fileName = dbFileName
|
|
|
- position = dbPosition
|
|
|
- }
|
|
|
- if position == 0 {
|
|
|
- position = dbPosition
|
|
|
+ if fileName == `` || position == 0 {
|
|
|
+ item, tmpErr := binlog.GetShowMaster()
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = tmpErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fileName = item.File
|
|
|
+ position = item.Position
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|