-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathall_keys.go
47 lines (38 loc) · 981 Bytes
/
all_keys.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
package goriak
import (
"errors"
riak "github.com/basho/riak-go-client"
)
type AllKeysCommand struct {
c *Command
builder *riak.ListKeysCommandBuilder
}
// AllKeys returns all keys in the set bucket.
// The response will be sent in multiple batches to callback
func (c *Command) AllKeys(callback func([]string) error) *AllKeysCommand {
builder := riak.NewListKeysCommandBuilder().
WithBucket(c.bucket).
WithBucketType(c.bucketType).
WithCallback(callback).
WithAllowListing(). // Required as of github.com/basho/riak-go-client 1.9.0
WithStreaming(true)
return &AllKeysCommand{
c: c,
builder: builder,
}
}
func (c *AllKeysCommand) Run(session *Session) (*Result, error) {
cmd, err := c.builder.Build()
if err != nil {
return nil, err
}
err = session.riak.Execute(cmd)
if err != nil {
return nil, err
}
res := cmd.(*riak.ListKeysCommand)
if !res.Success() {
return nil, errors.New("not successful")
}
return &Result{}, nil
}