bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/build/syncTokens/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"log"
     6  
     7  	"github.com/garyburd/redigo/redis"
     8  )
     9  
    10  var (
    11  	src = flag.String("src", "", "Source redis server")
    12  	dst = flag.String("dst", "", "Destination redis server")
    13  
    14  	key = flag.String("key", "accessTokens", "Redis Key to sync")
    15  )
    16  
    17  func main() {
    18  	flag.Parse()
    19  	if *src == "" || *dst == "" {
    20  		log.Fatal("Both src and dst redis servers required")
    21  	}
    22  
    23  	srcC, err := redis.Dial("tcp", *src)
    24  	if err != nil {
    25  		log.Fatal("Dialing src: ", err)
    26  	}
    27  	defer srcC.Close()
    28  	dstC, err := redis.Dial("tcp", *dst)
    29  	if err != nil {
    30  		log.Fatal("Dialing dst: ", err)
    31  	}
    32  	defer dstC.Close()
    33  
    34  	ser, err := redis.String(srcC.Do("DUMP", *key))
    35  	if err != nil {
    36  		log.Fatal("Dumping key: ", err)
    37  	}
    38  
    39  	_, err = dstC.Do("DEL", *key)
    40  	if err != nil {
    41  		log.Fatal("Deleting at destination: ", err)
    42  	}
    43  
    44  	_, err = dstC.Do("RESTORE", *key, 0, ser)
    45  	if err != nil {
    46  		log.Fatal("Restoring: ", err)
    47  	}
    48  
    49  	log.Println("Complete")
    50  }