-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_kv.go
131 lines (102 loc) · 3.15 KB
/
client_kv.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
127
128
129
130
131
package riago
import (
"time"
)
// Performs a Riak Get request.
func (c *Client) Get(req *RpbGetReq) (resp *RpbGetResp, err error) {
prof := NewProfile("get", string(req.GetBucket()))
defer c.instrument(prof, err)
resp = &RpbGetResp{}
err = c.retry(func() error {
return c.do(MsgRpbGetReq, req, resp, prof)
}, prof)
return
}
// Performs a Riak Put request.
func (c *Client) Put(req *RpbPutReq) (resp *RpbPutResp, err error) {
prof := NewProfile("put", string(req.GetBucket()))
defer c.instrument(prof, err)
resp = &RpbPutResp{}
err = c.retry(func() error {
return c.do(MsgRpbPutReq, req, resp, prof)
}, prof)
return
}
// Performs a Riak Del request.
func (c *Client) Del(req *RpbDelReq) (err error) {
prof := NewProfile("del", string(req.GetBucket()))
defer c.instrument(prof, err)
err = c.retry(func() error {
return c.do(MsgRpbDelReq, req, nil, prof)
}, prof)
return
}
// Perform a Riak Get Bucket request.
func (c *Client) GetBucket(req *RpbGetBucketReq) (resp *RpbGetBucketResp, err error) {
prof := NewProfile("get_bucket", string(req.GetBucket()))
defer c.instrument(prof, err)
resp = &RpbGetBucketResp{}
err = c.retry(func() error {
return c.do(MsgRpbGetBucketReq, req, resp, prof)
}, prof)
return
}
// Perform a Riak Set Bucket request.
func (c *Client) SetBucket(req *RpbSetBucketReq) (err error) {
prof := NewProfile("set_bucket", string(req.GetBucket()))
defer c.instrument(prof, err)
err = c.retry(func() error {
return c.do(MsgRpbSetBucketReq, req, nil, prof)
}, prof)
return
}
// Perform a Riak List Buckets request. The protobufs say that it will return
// multiple responses but it in fact does not.
func (c *Client) ListBuckets(req *RpbListBucketsReq) (resp *RpbListBucketsResp, err error) {
prof := NewProfile("list_buckets", "")
defer c.instrument(prof, err)
resp = &RpbListBucketsResp{}
err = c.do(MsgRpbListBucketsReq, req, resp, prof)
return
}
// Perform a Riak List Keys request. Returns multiple list keys responses.
func (c *Client) ListKeys(req *RpbListKeysReq) (resps []*RpbListKeysResp, err error) {
prof := NewProfile("list_keys", string(req.GetBucket()))
defer c.instrument(prof, err)
err = c.with(func(conn *Conn) (e error) {
// Issue the ListKeys request once
t := time.Now()
if e = conn.request(MsgRpbListKeysReq, req); e != nil {
return
}
prof.Request = time.Now().Sub(t)
// MapRed may produce multiple responses
resps = make([]*RpbListKeysResp, 0)
for {
// Receive the next response
resp := &RpbListKeysResp{}
t = time.Now()
if e = conn.response(resp); e != nil {
return
}
prof.Response += time.Now().Sub(t)
// Add the response to the result
resps = append(resps, resp)
// Stop receiving responses if the server tells us we're done
if resp.GetDone() {
break
}
}
return
}, prof)
return
}
// Perform a Riak Index (2i) request. The protobufs say that it will return
// multiple responses but it in fact does not.
func (c *Client) Index(req *RpbIndexReq) (resp *RpbIndexResp, err error) {
prof := NewProfile("index", string(req.GetBucket()))
defer c.instrument(prof, err)
resp = &RpbIndexResp{}
err = c.do(MsgRpbIndexReq, req, resp, prof)
return
}