41 lines
862 B
Go
41 lines
862 B
Go
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
|
|
}
|
|
}
|
|
|