mirror of https://github.com/ledisdb/ledisdb.git
bugfix for ledis dump
This commit is contained in:
parent
0a61b949e2
commit
0e717a34de
|
@ -1,11 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/siddontang/ledisdb/server"
|
"github.com/siddontang/ledisdb/client/go/ledis"
|
||||||
"net"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,12 +12,9 @@ var port = flag.Int("port", 6380, "ledis server port")
|
||||||
var sock = flag.String("sock", "", "ledis unix socket domain")
|
var sock = flag.String("sock", "", "ledis unix socket domain")
|
||||||
var dumpFile = flag.String("o", "./ledis.dump", "dump file to save")
|
var dumpFile = flag.String("o", "./ledis.dump", "dump file to save")
|
||||||
|
|
||||||
var fullSyncCmd = []byte("*2\r\n$8\r\nfullsync\r\n$3\r\nnew\r\n") //fullsync
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
var c net.Conn
|
|
||||||
var err error
|
var err error
|
||||||
var f *os.File
|
var f *os.File
|
||||||
|
|
||||||
|
@ -30,30 +25,25 @@ func main() {
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
var addr string
|
||||||
if len(*sock) != 0 {
|
if len(*sock) != 0 {
|
||||||
c, err = net.Dial("unix", *sock)
|
addr = *sock
|
||||||
} else {
|
} else {
|
||||||
addr := fmt.Sprintf("%s:%d", *host, *port)
|
addr = fmt.Sprintf("%s:%d", *host, *port)
|
||||||
c, err = net.Dial("tcp", addr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
c := ledis.NewConnSize(addr, 16*1024, 4096)
|
||||||
println(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
println("dump begin")
|
println("dump begin")
|
||||||
|
|
||||||
if _, err = c.Write(fullSyncCmd); err != nil {
|
if err = c.Send("fullsync"); err != nil {
|
||||||
println(err.Error())
|
println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rb := bufio.NewReaderSize(c, 16*1024)
|
if err = c.ReceiveBulkTo(f); err != nil {
|
||||||
|
|
||||||
if err = server.ReadBulkTo(rb, f); err != nil {
|
|
||||||
println(err.Error())
|
println(err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue