Ignite Rest Api - Increment method

84 Views Asked by At

I am not able to get the incremented value, when i do a get i get the value which i had put initially and not after increment

1> curl 'http://localhost:8080/ignite?cmd=put&cacheName=mycache&key=mykey&val=1'

{"successStatus":0,"affinityNodeId":"512ab48f-8c0b-4381-a59b-c32b55d91b08","error":null,"response":true,"sessionToken":null}% 

I had put a value 0f "1" to "mykey"

2> curl 'http://localhost:8080/ignite?cmd=incr&cacheName=mycache&key=mykey&delta=1'

{"successStatus":0,"error":null,"response":1,"sessionToken":null}

I try to increment it by 1 but i get value 0f "1" for "mykey"

3> curl 'http://localhost:8080/ignite?cmd=incr&cacheName=mycache&key=mykey&delta=1'
   
{"successStatus":0,"error":null,"response":2,"sessionToken":null}%  

I try to increment it by 1 again and i get value 0f "2" for "mykey"

4> curl 'http://localhost:8080/ignite?cmd=get&cacheName=mycache&key=mykey'

{"successStatus":0,"affinityNodeId":"512ab48f-8c0b-4381-a59b-c32b55d91b08","error":null,"response":"1","sessionToken":null}% 

I try to get value of "mykey" and get value 0f "1"

I want to get the incremented value which is "2" in my case. Can anyone please guide.

1

There are 1 best solutions below

0
Igor Belyakov On

The Increment and Decrement REST API endpoints are designed to work with IgniteAtomicLong data structures, and not with a specific cache value.

Unfortunately, there is a mistake in the documentation, in fact, the listed cacheName parameter is not applicable for these endpoints, which could be confusing, I've filed a documentation ticket regarding that issue.

As a workaround, you can try to use the Compare-And-Swap endpoint to do an atomic update for a specific value in the cache. More details regarding it can be found here.