selfcare init
This commit is contained in:
40
proxy_go/Nredis/canal_info.go
Normal file
40
proxy_go/Nredis/canal_info.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package Nredis
|
||||
|
||||
import (
|
||||
l4g "proxy/logger"
|
||||
)
|
||||
|
||||
type BinLogPos struct {
|
||||
File string `redis:"file"`
|
||||
Position uint32 `redis:"position"`
|
||||
}
|
||||
|
||||
func RdbSetBinLogPos(file string, pos uint32) error {
|
||||
err := rdb.HMSet(ctx, "binlogpos", "file", file, "position", pos).Err()
|
||||
if err != nil {
|
||||
l4g.RedisLog.Errorf("HMSet binlogpos %s %d, err: %v", file, pos, err)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func RdbGetBinLogPos() *BinLogPos {
|
||||
// Get the map. The same approach works for HmGet().
|
||||
res := rdb.HGetAll(ctx, "binlogpos")
|
||||
err := res.Err()
|
||||
if err != nil {
|
||||
l4g.RedisLog.Errorf("HGetAll binlogpos, err: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Scan the results into the struct.
|
||||
var pos BinLogPos
|
||||
if err = res.Scan(&pos); err != nil {
|
||||
l4g.RedisLog.Errorf("HGetAll Scan binlogpos, err: %v", err)
|
||||
return nil
|
||||
} else {
|
||||
l4g.RedisLog.Debugf("Get binlogpos, [%v]", pos)
|
||||
return &pos
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user