forked from bpaquet/aerodis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
as_tools.go
59 lines (52 loc) · 1.38 KB
/
as_tools.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
package main
import (
as "github.com/aerospike/aerospike-client-go"
ase "github.com/aerospike/aerospike-client-go/types"
)
func createReadPolicy() *as.BasePolicy {
policy := as.NewPolicy()
policy.ConsistencyLevel = as.CONSISTENCY_ONE
policy.ReplicaPolicy = as.MASTER_PROLES
return policy
}
func fillWritePolicy(writePolicy *as.WritePolicy) {
writePolicy.CommitLevel = as.COMMIT_MASTER
}
func createWritePolicyGeneration(generation uint32, ttl int) *as.WritePolicy {
policy := as.NewWritePolicy(0, as.TTLDontUpdate)
if ttl != -1 {
policy = as.NewWritePolicy(0, uint32(ttl))
}
fillWritePolicy(policy)
if generation > 0 {
policy.GenerationPolicy = as.EXPECT_GEN_EQUAL
policy.Generation = generation
}
return policy
}
func createWritePolicyEx(ttl int, createOnly bool) *as.WritePolicy {
if ttl == -2 {
policy := as.NewWritePolicy(0, as.TTLDontExpire)
fillWritePolicy(policy)
return policy
}
policy := as.NewWritePolicy(0, as.TTLDontUpdate)
if ttl != -1 {
policy = as.NewWritePolicy(0, uint32(ttl))
}
fillWritePolicy(policy)
if createOnly {
policy.RecordExistsAction = as.CREATE_ONLY
}
return policy
}
func buildKey(ctx *context, key []byte) (*as.Key, error) {
return as.NewKey(ctx.ns, ctx.set, string(key))
}
func errResultCode(err error) ase.ResultCode {
switch err.(type) {
case ase.AerospikeError:
return err.(ase.AerospikeError).ResultCode()
}
return -15000
}