forked from DataCentricAlliance/aerodrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaerospike_put.go
35 lines (32 loc) · 836 Bytes
/
aerospike_put.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
package main
import (
aerospike "github.com/aerospike/aerospike-client-go"
"time"
)
type AeroPut struct {
namespace string
set string
pk string
data struct {
Bins map[string]interface{} `json:"bins"`
Meta struct {
Ttl int32 `json:"ttl"`
Generation int32 `json:"version"`
} `json:"meta"`
}
}
func (storage *AerospikeStorage) Put(query AeroPut) bool {
var (
err error
Key *aerospike.Key
policy *aerospike.WritePolicy
)
policy = aerospike.NewWritePolicy(query.data.Meta.Generation, query.data.Meta.Ttl)
policy.Timeout = time.Duration(config.Aerospike.WriteTimeout) * time.Millisecond
policy.SendKey = true
Key, _ = aerospike.NewKey(query.namespace, query.set, query.pk)
if err = storage.Client.Put(policy, Key, query.data.Bins); err != nil {
panic(err)
}
return true
}