aerospike / aerospike-client-go

Aerospike Client Go
Apache License 2.0
429 stars 199 forks source link

increment counter for map #385

Closed artman92 closed 1 year ago

artman92 commented 1 year ago

I'd like to implement an incremental counter for map - Right now I am using

aerospike.PutOp(aerospike.NewBin("binName", map[string]string{
constants.key1:     fmt.Sprintf("%v", a),
constants.key2:    fmt.Sprintf("%v",b),
})
_, err = asClient.Operate(nil, asKey, ops...)

My worry is that with too many concurrent queries I want to lock it so that the values will be correct everytime.

khaf commented 1 year ago

You need to use CDT operations:

    op := as.MapIncrementOp(as.DefaultMapPolicy(), "binName", "keyNameInsideMap", 1)
    res, err := client.Operate(nil, key, op)
khaf commented 1 year ago

Closing the issue. Don't hesitate to open a new ticket for any questions you may have.