-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
hll_get.go
67 lines (54 loc) · 1.27 KB
/
hll_get.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
package goriak
import (
riak "github.com/basho/riak-go-client"
"errors"
)
type FetchHyperLogLogCommand struct {
builder *riak.FetchHllCommandBuilder
key string
}
type HyperLogLogResult struct {
Key string
NotFound bool
Cardinality uint64
}
func (c *Command) GetHyperLogLog(key string) *FetchHyperLogLogCommand {
b := riak.NewFetchHllCommandBuilder().
WithBucket(c.bucket).
WithBucketType(c.bucketType).
WithKey(key)
return &FetchHyperLogLogCommand{
builder: b,
key: key,
}
}
func (c *FetchHyperLogLogCommand) WithPr(pr uint32) *FetchHyperLogLogCommand {
c.builder.WithPr(pr)
return c
}
func (c *FetchHyperLogLogCommand) WithR(r uint32) *FetchHyperLogLogCommand {
c.builder.WithPr(r)
return c
}
func (c *FetchHyperLogLogCommand) Run(session *Session) (*HyperLogLogResult, error) {
cmd, err := c.builder.Build()
if err != nil {
return nil, err
}
err = session.riak.Execute(cmd)
if err != nil {
return nil, err
}
res, ok := cmd.(*riak.FetchHllCommand)
if !ok {
return nil, errors.New("Could not convert result")
}
if !res.Success() {
return nil, errors.New("Execution not successful")
}
return &HyperLogLogResult{
NotFound: res.Response.IsNotFound,
Cardinality: res.Response.Cardinality,
Key: c.key,
}, nil
}