Skip to content

Instantly share code, notes, and snippets.

@dictav
Created October 30, 2017 05:23
Show Gist options
  • Save dictav/a161dcdaea7ab96d7ea96b53fca7cf54 to your computer and use it in GitHub Desktop.
Save dictav/a161dcdaea7ab96d7ea96b53fca7cf54 to your computer and use it in GitHub Desktop.
package main
import (
as "github.com/aerospike/aerospike-client-go"
astp "github.com/aerospike/aerospike-client-go/types"
"math"
"time"
)
type hoge struct {
Name string `as:"name"`
TTL uint32 `asm:"ttl"`
Gen uint32 `asm:"gen"`
}
func main() {
client, err := as.NewClient("127.0.0.1",3000)
if err != nil {
panic(err)
}
key,err := as.NewKey("test", "test", "user0000")
if err != nil {
panic(err)
}
data := hoge{ Name:"hello" }
wp := as.NewWritePolicy(0, math.MaxUint32)
err = client.PutObject(wp, key, &data)
if err != nil {
panic(err)
}
rp := as.NewPolicy()
ret := hoge{}
err = client.GetObject(rp, key, &ret)
if err != nil {
panic(err)
}
println(ttl(ret.TTL), ret.TTL)
}
func ttl(sec uint32) uint32 {
ttl1 := math.MaxUint32 - sec
ttl2 := time.Now().Unix() - int64(astp.CITRUSLEAF_EPOCH+ttl1)
return uint32(ttl2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment