-
Notifications
You must be signed in to change notification settings - Fork 30
/
command_prefix.go
55 lines (44 loc) · 1.07 KB
/
command_prefix.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
package shell
import (
"fmt"
"io"
"strconv"
"github.com/chrislusf/vasto/goclient/vs"
)
func init() {
commands = append(commands, &commandPrefix{})
}
type commandPrefix struct {
}
func (c *commandPrefix) Name() string {
return "prefix"
}
func (c *commandPrefix) Help() string {
return "<prefix> [<limit> <lastSeenKey>], prefix should also be the partition key"
}
func (c *commandPrefix) Do(vastoClient *vs.VastoClient, args []string, commandEnv *commandEnv, writer io.Writer) error {
if commandEnv.clusterClient == nil {
return errNoKeyspaceSelected
}
prefix := []byte(args[0])
limit := uint32(100)
var lastSeenKey []byte
if len(args) >= 2 {
t, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return err
}
limit = uint32(t)
}
if len(args) >= 3 {
lastSeenKey = []byte(args[2])
}
keyValues, err := commandEnv.clusterClient.GetByPrefix(nil, prefix, limit, lastSeenKey)
if err != nil {
return err
}
for _, keyValue := range keyValues {
fmt.Fprintf(writer, "%s : %s\n", string(keyValue.GetKey()), string(keyValue.GetValue()))
}
return nil
}