The most common question I hear about Couchbase and other NoSQL databases is how to generate unique keys for records - or more specificly - how to replicate the AUTO INCREMENT f
First of all according to couchbase documentation functions increment
and decremant
are "atomic" within cluster. So if you use them to generate "autoincrement" all should work fine.
But if you want to enshure that while you save new item in the couchbase you will not override existing (situation like "BOTH Couchbase instances could return 1501") you can use store operation with StoreMode.Add
. So if you call at the same time couchbase.store(StoreMode.Add, "request:1501",value)
, one request will finish with success, other will fail and you can catch this "fail" and try to repeat that store operation again (with getting new autoincremented id for new key)