forked from jcoene/riago
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkv.go
69 lines (59 loc) · 1.81 KB
/
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
package riago
// Performs a Riak Get request.
func (c *Conn) Get(req *RpbGetReq) (resp *RpbGetResp, err error) {
resp = new(RpbGetResp)
err = c.do(MsgRpbGetReq, req, resp)
return
}
// Performs a Riak Put request.
func (c *Conn) Put(req *RpbPutReq) (resp *RpbPutResp, err error) {
resp = new(RpbPutResp)
err = c.do(MsgRpbPutReq, req, resp)
return
}
// Performs a Riak Del request.
func (c *Conn) Del(req *RpbDelReq) error {
return c.do(MsgRpbDelReq, req, nil)
}
// Perform a Riak Get Bucket request.
func (c *Conn) GetBucket(req *RpbGetBucketReq) (resp *RpbGetBucketResp, err error) {
resp = new(RpbGetBucketResp)
err = c.do(MsgRpbGetBucketReq, req, resp)
return
}
// Perform a Riak Set Bucket request.
func (c *Conn) SetBucket(req *RpbSetBucketReq) error {
return c.do(MsgRpbSetBucketReq, req, nil)
}
// Perform a Riak List Buckets request. The protobufs say that it will return
// multiple responses but it in fact does not.
func (c *Conn) ListBuckets(req *RpbListBucketsReq) (resp *RpbListBucketsResp, err error) {
resp = new(RpbListBucketsResp)
err = c.do(MsgRpbListBucketsReq, req, resp)
return
}
// Perform a Riak List Keys request. Returns multiple list keys responses.
func (c *Conn) ListKeys(req *RpbListKeysReq) ([]*RpbListKeysResp, error) {
var resps []*RpbListKeysResp
if err := c.request(MsgRpbListKeysReq, req); err != nil {
return nil, err
}
for {
resp := new(RpbListKeysResp)
if err := c.response(resp); err != nil {
return nil, err
}
resps = append(resps, resp)
if resp.GetDone() {
break
}
}
return resps, nil
}
// Perform a Riak Index (2i) request. The protobufs say that it will return
// multiple responses but it in fact does not.
func (c *Conn) Index(req *RpbIndexReq) (resp *RpbIndexResp, err error) {
resp = new(RpbIndexResp)
err = c.do(MsgRpbIndexReq, req, resp)
return
}