Strange problems with increment

Hi,

I’m running the following code on couchbase 2.5.1 and java sdk versions 1.3.2 and 1.4.2

	bucket.couchbaseClient.set("incrementInt4", 4).get() mustEqual true
	bucket.couchbaseClient.set("incrementInt", 3).get() mustEqual true
	System.out.println(bucket.couchbaseClient.get("incrementInt4").toString)
	System.out.println(bucket.couchbaseClient.get("incrementInt").toString)

    //STRANGE incr does not seem to work, counter is not incremented
	bucket.couchbaseClient.incr("incrementInt", 1) 

	System.out.println(bucket.couchbaseClient.get("incrementInt").toString)

Its scala, which explains the lack of ‘;’

I get the following output from the console

4
3
3

I would expect the last line to be 4. Also the incr returns -1, which means that the key did not exist, according to the reference documentation

In the ui for couchbase, the keys has the following values

incrementInt "Aw==" incrementInt4 "BA=="

Why are the keys not stored as integers. I can’t get the above to make sense

Thanks
Niels

Can you either do a incr with a default value or set with the number as a string?

Also, the user interface only shows you JSON nicely, which is not the case for a number that you are handling with incr/decr.

I managed to figure out the problem

If you set a value like a string, eg “5” you can increment and decrement it afterwards. Settings a value like 5 does not work as it get transformed to a byte representation of the string 5 or something like that

Also it works if I use incr with a default value. However, incr does only do the set if the key didn’t exist and don’t do any increment

It was a little confusing

Best Regards
Niels