Skip to content

Instantly share code, notes, and snippets.

@alicebob
Created November 27, 2015 10:33
Show Gist options
  • Save alicebob/67930e7a66ec8449609a to your computer and use it in GitHub Desktop.
Save alicebob/67930e7a66ec8449609a to your computer and use it in GitHub Desktop.
int64 in Aerospike
package main
import (
"fmt"
"time"
as "github.com/aerospike/aerospike-client-go"
)
const lua = `
function echoint(r, now)
info("call echoint with %d", now)
return now
end
`
func main() {
client, err := as.NewClient("127.0.0.1", 3000)
if err != nil {
panic(err)
}
task, err := client.RegisterUDF(
nil,
[]byte(lua),
"echoint.lua",
as.LUA,
)
if err != nil {
panic(err)
}
if err, ok := <-task.OnComplete(); ok && err != nil {
panic(err)
}
fmt.Printf("RegisterUDF done\n")
key, _ := as.NewKey("test", "test", "test")
now := time.Now().UnixNano()
fmt.Printf("now: %d\n", now)
res, err := client.Execute(
nil,
key,
"echoint",
"echoint",
as.IntegerValue(now),
)
if err != nil {
panic(err)
}
fmt.Printf("res: %+v\n", res)
if have, want := res, now; have != want {
fmt.Printf("oops: have %d, want %d\n", have, want)
}
} 1,1 Top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment