-
Notifications
You must be signed in to change notification settings - Fork 11
/
godis-cli-bigkey.go
42 lines (39 loc) · 945 Bytes
/
godis-cli-bigkey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"flag"
"fmt"
"os"
"github.com/erpeng/godis-cli-bigkey/pool"
"github.com/erpeng/godis-cli-bigkey/rdb"
)
func main() {
debug := flag.Bool("debug", false, "open debug mode")
topN := flag.Int("topn", 100, "output topn keys")
totalLen := flag.Bool("totallen", true, "get total len (key and meta) or only value len")
flag.Parse()
rdb.DEBUG = *debug
rdb.TOTALLEN = *totalLen
f, err := os.Open("./rdb.rdb")
if err != nil {
fmt.Printf("Open rdb file error:%v", err)
os.Exit(1)
}
b, err := rdb.ReadBytes(f, 5)
if err != nil {
fmt.Printf("Read Rdb magic error:%v", err)
os.Exit(1)
}
if !rdb.EqualBytes(b, []byte(rdb.RDB_MAGIC)) {
fmt.Printf("Error:%s\n", "invalid rdb file ")
os.Exit(1)
}
b, err = rdb.ReadBytes(f, 4)
if err != nil {
fmt.Printf("Read Rdb version error:%v", err)
os.Exit(1)
}
fmt.Printf("\rRdb Version:%s\n", string(b))
pool.InitLen(*topN)
rdb.Load(f)
pool.PrintPool()
}