Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Atomic counters in Couchbase

I wanted to know if Couchbase support consistent incremental Counters. From what I've read in this doc, it does not, it just encapsulates a read/write operation so you won't need to do it yourself. Of course this doesn't work for me because the data might change since the time you read the data from the database.

like image 469
Idan Shechter Avatar asked Dec 04 '25 12:12

Idan Shechter


1 Answers

Couchbase absolutely does, just like memcached and Membase Server, it supports the incr/decr operations atomically within a cluster.

cb.set("mykey", 1)
x = cb.incr("mykey") 
puts x #=> 2

incr is both writing and returning the resulting value.

"The update operation occurs on the server and is provided at the protocol level." means that it is atomic on the cluster, and executed by the server.

"This simplifies what would otherwise be a two-stage get and set operation." means that instead of a two-stage operation, it is a single operation!

like image 88
scalabl3 Avatar answered Dec 07 '25 04:12

scalabl3