I’d like to implement an atomic counter. Ideally I can use Client.Add(), but the method does not return the new value of the bin. So I resort to a UDF that increases a number typed bin and return it. However the interface{} returned from Client.Execute() is of type int. How can I make the returned type become int64? Or are there any better way to get int64 counters?
Here is my UDF in case it’s useful:
function add(topRec, intBin, intVal)
if type(intVal) ~= "number" then
error("input value is not a number")
end
if not aerospike:exists(topRec) then
aerospike:create(topRec)
end
local v = topRec[intBin]
if v == nil then
v = intVal
else
if type(v) ~= "number" then
error("value in the bin is not a number")
end
v = v + intVal
end
topRec[intBin] = v
aerospike:update(topRec)
return v
end
It seems better to use int64 as strconv.ParseInt() does.
Also looks right now the db (or Go client) does not support storing/fetching uint64?
I actually faced this problem and have to encode uint64 into a customized base 64 string. Or I can actually use uint64 as LDT item’s key directly?