-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.go
126 lines (110 loc) · 3 KB
/
dump.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"bytes"
"fmt"
"github.com/gushitong/rekkles/stor"
"github.com/gushitong/rekkles/ut"
"io"
)
func DumpList(key []byte, txn stor.Transaction) {
var queueLen int64
encoder, _ := NewListEncoder(key)
val, err := txn.Get(encoder.QueueKey())
if err != nil {
panic(err)
}
queueLen, err = ut.Bytes2Int64(val)
if err != nil && err != io.EOF {
panic(err)
}
dumpStr := fmt.Sprintf("[List]: %s ", string(key))
prefix := encoder.Prefix()
it := txn.NewIterator(stor.DefaultIteratorOptions)
defer it.Close()
for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
item := it.GetItem()
listKey := item.Key()
value, err := item.Value()
if err != nil {
panic(err)
}
i, err := encoder.DecodeSeq(listKey)
if err != nil {
panic(err)
}
dumpStr += fmt.Sprintf("%d %s ", i, string(value))
}
dumpStr += fmt.Sprintf("(len %d)", queueLen)
fmt.Println(dumpStr)
}
func DumpSet(key []byte, txn stor.Transaction) {
encoder, _ := NewSetEncoder(key)
it := txn.NewIterator(stor.DefaultIteratorOptions)
defer it.Close()
dumpStr := fmt.Sprintf("[Queue]: %s ", string(key))
for it.Seek(encoder.Prefix()); it.ValidForPrefix(encoder.Prefix()); it.Next() {
item := it.GetItem()
member, err := encoder.DecodeMember(item.Key())
if err != nil {
panic(err)
}
if value, _ := item.Value(); bytes.Compare(value, SetMemberValue) != 0 {
panic("Err ser member value")
}
dumpStr += fmt.Sprintf(" %s", string(member))
}
queueLen, err := txn.Get(encoder.QueueKey())
if err != nil {
panic(err)
}
dumpStr += fmt.Sprintf(" (len %s)", queueLen)
fmt.Println(dumpStr)
}
func DumpZset(key []byte, txn stor.Transaction) {
encoder, _ := NewZsetEncoder(key)
it := txn.NewIterator(stor.DefaultIteratorOptions)
defer it.Close()
dumpStr := fmt.Sprintf("[Zset]: %s ", string(key))
for it.Seek(encoder.MemberPrefix()); it.ValidForPrefix(encoder.MemberPrefix()); it.Next() {
item := it.GetItem()
member, err := encoder.DecodeMemberKey(item.Key())
if err != nil {
panic(err)
}
if value, err := item.Value(); err != nil {
panic("Err ser member value")
} else {
dumpStr += fmt.Sprintf("%s:%s ", string(member), string(value))
}
}
queueLen, err := txn.Get(encoder.QueueKey())
if err != nil {
panic(err)
}
dumpStr += fmt.Sprintf(" (len %s)", queueLen)
fmt.Println(dumpStr)
}
func DumpZsetScore(key []byte, txn stor.Transaction) {
encoder, _ := NewZsetEncoder(key)
it := txn.NewIterator(stor.DefaultIteratorOptions)
defer it.Close()
dumpStr := fmt.Sprintf("[Z]: %s ", string(key))
for it.Seek(encoder.ScorePrefix()); it.ValidForPrefix(encoder.ScorePrefix()); it.Next() {
item := it.GetItem()
score, err := encoder.DecodeScoreKey(item.Key())
if err != nil {
panic(err)
}
if value, err := item.Value(); err != nil {
panic("Err zset member")
} else {
dumpStr += fmt.Sprintf("%d:%s ", score, string(value))
}
}
queueLen, err := txn.Get(encoder.QueueKey())
if err != nil {
panic(err)
}
dumpStr += fmt.Sprintf(" (len %s)", queueLen)
fmt.Println(dumpStr)
}