项目作者: yametech

项目描述 :
redis replication canal slave
高级语言: Go
项目地址: git://github.com/yametech/canal.git
创建时间: 2019-09-25T06:19:12Z
项目社区:https://github.com/yametech/canal

开源协议:

下载


Canal                       中文

Build Status
Go Report Card
License

Introduction

Canal supports redis 2.x to 5.x and forward compatible replication tools with hybrid (rdb + aof) protocol

Scenes

  • Redis data synchronization across computer rooms
  • Heterogeneous data migration; such as Redis to mysql, MQ, ES, etc.

Design

Simulate the redis slave, then go to dump the rdb and aof of the redis master (add the architecture design diagram later)

Features

  • Support redis 2.x to 5.x data synchronization
  • Support full synchronization and incremental synchronization (continued resume)
  • Support failover
  • Faster

Company Internal use

  • 2k + redis instance data synchronization

Usage

  1. go get github.com/yametech/canal

Basic Usage

  1. package main
  2. import (
  3. "github.com/yametech/canal"
  4. "log"
  5. "os"
  6. "time"
  7. )
  8. type printer struct{}
  9. func (p *printer) Command(cmd *canal.Command) error {
  10. log.Printf("[PRINTER] cmd=%v\n", cmd)
  11. return nil
  12. }
  13. func main() {
  14. log.SetOutput(os.Stdout)
  15. cfg, err := canal.NewConfig(
  16. "127.0.0.1:6379",
  17. canal.DialKeepAlive(time.Hour*16800),
  18. canal.DialWithLocalPort(6379), // use specified local port
  19. )
  20. if err != nil {
  21. panic(err)
  22. }
  23. repl, err := canal.NewCanal(cfg)
  24. if err != nil {
  25. panic(err)
  26. }
  27. defer repl.Close()
  28. if err := repl.Run(&printer{}); err != nil {
  29. panic(err)
  30. }
  31. }

Use of breakpoint resume

  1. // starting from the location of an instance example
  2. package main
  3. import (
  4. "github.com/yametech/canal"
  5. "log"
  6. "os"
  7. "time"
  8. )
  9. type printer struct{}
  10. func (p *printer) Command(cmd *canal.Command) error {
  11. log.Printf("[PRINTER] cmd=%v\n", cmd)
  12. return nil
  13. }
  14. func main() {
  15. log.SetOutput(os.Stdout)
  16. cfg, err := canal.NewConfig(
  17. "127.0.0.1:8888",
  18. canal.DialKeepAlive(time.Minute*5),
  19. )
  20. if err != nil {
  21. panic(err)
  22. }
  23. repl, err := canal.FromOffsetCanal(cfg, "0cc79e52c7cdcaa58535bb2ce23f46ee1343246c", 111)
  24. if err != nil {
  25. panic(err)
  26. }
  27. defer repl.Close()
  28. if err := repl.Run(&printer{}); err != nil {
  29. panic(err)
  30. }
  31. }

Failover usage

  1. //
  2. type printer struct{}
  3. func (p *printer) Command(cmd *canal.Command) error {
  4. log.Printf("[PRINTER] cmd=%s\n", cmd.String())
  5. return nil
  6. }
  7. func main() {
  8. log.SetOutput(os.Stdout)
  9. cfg, err := canal.NewConfig(
  10. "127.0.0.1:6379",
  11. canal.DialKeepAlive(time.Minute*5),
  12. // canal.DialPassword(""),
  13. )
  14. if err != nil {
  15. panic(err)
  16. }
  17. cfg.ReplMaster()
  18. repl, err := canal.NewCanal(cfg)
  19. if err != nil {
  20. panic(err)
  21. }
  22. defer repl.Close()
  23. if err := repl.Run(&printer{}); err != nil {
  24. panic(err)
  25. }
  26. }

TODO

  • Support c / s structure, grpc cross platform use
  • redis 6.x
  • Support etcd, zk, consul and other storage position
  • Support cluster
  • Automatic maintenance of redis topology structure