Is it possible to use Couchbase's Atomic Counters with the Spring Connector? Currently I have a repository for a specific document type and want to have an atomic counter for every document. I know that the Java SDK offers the functionality but I was not able to find an equivalent action for Spring.
As I know Spring doesn't have support for counters but it's pretty simple to write own repository:
@Repository
public class CountersRepository {
private static final long INITIAL_COUNTER_VALUE = 1;
@Autowired
private Bucket bucket;
public void incCounter(final String counter) {
bucket.counter(counter, 1, INITIAL_COUNTER_VALUE);
}
public void decCounter(final String counter) {
bucket.counter(counter, -1, INITIAL_COUNTER_VALUE);
}
public Long getCounterValue(final String counter) {
return bucket.counter(counter, 0).content();
}
}
来源:https://stackoverflow.com/questions/42507421/atomic-counters-in-spring-with-couchbase