-
-
Save sideshowcoder/8d3ae572bc8e0742ae64 to your computer and use it in GitHub Desktop.
Running an incr combined with getAndLock results in a value of -1 without getAndLock it works as intended. With a locked value incr behaves like the key does not exist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.couchbase.client.CouchbaseClient; | |
import net.spy.memcached.CASValue; | |
import java.net.URI; | |
import java.util.Arrays; | |
import java.util.List; | |
public class CouchbaseExample { | |
public static void main(String[] args) throws Exception { | |
List<URI> hosts = Arrays.asList(new URI("http://localhost:8091/pools")); | |
CouchbaseClient client = new CouchbaseClient(hosts, "default", ""); | |
long beforeValue = client.incr("my-counter", 1, 0); | |
System.out.println("Incremented value is: " + beforeValue); // => Incremented value is: 0 | |
CASValue<Object> result = client.getAndLock("my-counter", 1000); | |
long afterValue = client.incr("my-counter", 1, 0); | |
System.out.println("Incremented value is: " + afterValue); // => Incremented value is: -1 | |
client.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment