Skip to content

Instantly share code, notes, and snippets.

@alicebob
Created November 27, 2015 10:33
Show Gist options
  • Select an option

  • Save alicebob/67930e7a66ec8449609a to your computer and use it in GitHub Desktop.

Select an option

Save alicebob/67930e7a66ec8449609a to your computer and use it in GitHub Desktop.

Revisions

  1. Harmen created this gist Nov 27, 2015.
    54 changes: 54 additions & 0 deletions aeint.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    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