-
Notifications
You must be signed in to change notification settings - Fork 50
/
aerospike.go
43 lines (35 loc) · 888 Bytes
/
aerospike.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
package aerospike
import (
"github.com/aerospike/aerospike-client-go/v5"
)
type Client struct {
*aerospike.Client
namespace string
}
func New(client *aerospike.Client, namespace string) *Client {
return &Client{
Client: client,
namespace: namespace,
}
}
func (c *Client) Truncate(set string) error {
return c.Client.Truncate(nil, c.namespace, set, nil)
}
func (c *Client) InsertBinMap(set, key string, binMap map[string]interface{}) error {
aerospikeKey, err := aerospike.NewKey(c.namespace, set, key)
if err != nil {
return err
}
bins := prepareBins(binMap)
return c.PutBins(nil, aerospikeKey, bins...)
}
func prepareBins(binmap map[string]interface{}) []*aerospike.Bin {
var bins []*aerospike.Bin
for binName, binData := range binmap {
if binName == "$extend" {
continue
}
bins = append(bins, aerospike.NewBin(binName, binData))
}
return bins
}