I am not a developer but the sandbox makes it so easy to try things out that I did the following and seem I am able to get the value of a bin before it gets updated and returned in a single shot.
I first used the sample on this page of the sandbox to create a new record:
import (
"fmt"
"github.com/aerospike/aerospike-client-go/v6"
)
// Establishes a connection to the server
client, err := aerospike.NewClient("127.0.0.1", 3000)
// Creates a key with the namespace "sandbox", set "ufodata", and user key 5001
key, err := aerospike.NewKey("sandbox", "ufodata", 5001)
// Create posted bin to insert
posted := aerospike.NewBin("posted", 20220602)
// Update the record
record, err := client.Operate(nil, key,
aerospike.PutOp(posted),
aerospike.MapPutOp(aerospike.DefaultMapPolicy(), "report", aerospike.NewValue("city"), aerospike.NewValue("Ypsilanti")),
aerospike.GetBinOp("report"))
// Do something
fmt.Printf("Record: %v", record.Bins)
// Close the connection to the server
client.Close()
I then tried the following to basically update the bin “posted” but read its value prior to the update and got the expected value… running a second time then shows the updated value:
import (
"fmt"
"github.com/aerospike/aerospike-client-go/v6"
)
// Establishes a connection to the server
client, err := aerospike.NewClient("127.0.0.1", 3000)
// Creates a key with the namespace "sandbox", set "ufodata", and user key 5001
key, err := aerospike.NewKey("sandbox", "ufodata", 5001)
// Create posted bin to insert
posted := aerospike.NewBin("posted", 20220603)
// Update the record
record, err := client.Operate(nil, key,
aerospike.GetBinOp("posted"),
aerospike.PutOp(posted),
aerospike.MapPutOp(aerospike.DefaultMapPolicy(), "report", aerospike.NewValue("city"), aerospike.NewValue("Ypsilanti")),
aerospike.GetBinOp("report"))
// Do something
fmt.Printf("Record: %v", record.Bins)
// Close the connection to the server
client.Close()
But I don’t know whether this is the proper way to use the API. I am pretty sure this is supposed to work, including within CDTs, but curious if it doesn’t work for you somehow.