Atomic operations (counters)

I am using atomic operations to maintain several counters which works fine, but I am not sure how to get the current counter value, I tried to use:

bucket.Get( key ) and bucket.GetDocument( key )

but both gave exceptions. I am currently using another approach:

bucket.Increment( key, 0, 0, TimeSpan.FromHours( 1 ) )

e.g. delta = 0. But is this the correct way or a hack?

@jacob_michaelsen -

Can you post the exception information? I suspect it’s a type cast issue because Couchbase server stores the counter value as an ASCII string.

-Jeff

@jmorris

You are right, Get(string)( key ) works.

Is misread the document stating “The reason is that the server stores the value as the ASCII representation and not as a 64-bit integer.” and reversed it, so thought it was saved as a 64-bit integer.

Thanx

1 Like

@jacob_michaelsen -

Its the same reason you cannot start with a via an upsert/insert and then use increment/decrement on it…there are optimizations done internally which require special packet encoding and formatting.

-Jeff