forked from DataCentricAlliance/aerodrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaerospike_get.go
69 lines (60 loc) · 1.45 KB
/
aerospike_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
68
69
package main
import (
"github.com/aerospike/aerospike-client-go"
"time"
)
type AeroGet struct {
namespace string
set string
pk []string
}
func (storage *AerospikeStorage) BatchGet(query AeroGet) *[]*AeroResponse {
var (
records []*aerospike.Record
record *aerospike.Record
err error
Key *aerospike.Key
Keys []*aerospike.Key
Bins []*AeroResponse
)
policy := aerospike.NewPolicy()
policy.Timeout = time.Duration(config.Aerospike.ReadTimeout) * time.Millisecond
for idx := range query.pk {
Key, _ = aerospike.NewKey(query.namespace, query.set, query.pk[idx])
Keys = append(Keys, Key)
}
if records, err = storage.Client.BatchGet(policy, Keys); err != nil {
panic("timeout")
return nil
}
if len(records) == 0 {
return nil
}
for idx := range records {
record = records[idx]
if record == nil {
Bins = append(Bins, nil)
} else {
Bins = append(Bins, RecordToAeroResponse(record))
}
}
return &Bins
}
func (storage *AerospikeStorage) Get(query AeroGet) *AeroResponse {
var (
record *aerospike.Record
err error
Key *aerospike.Key
)
policy := aerospike.NewPolicy()
policy.Timeout = time.Duration(config.Aerospike.ReadTimeout) * time.Millisecond
Key, _ = aerospike.NewKey(query.namespace, query.set, query.pk[0])
if record, err = storage.Client.Get(policy, Key); err != nil {
panic("timeout")
return nil
}
if record == nil {
return nil
}
return RecordToAeroResponse(record)
}