Friday, August 5, 2016

MemcacheService, BigInteger, and Byte Array

MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
IdentifiableValue oldValue = syncCache.getIdentifiable(key);
BigInteger.valueOf(0).toByteArray()
byte[] newValue = increment((byte[]) oldValue.getValue());
new BigInteger(newValue).intValue()
syncCache.putIfUntouched(key, oldValue, newValue)
break;
Thread.sleep(delayMs);

private byte[] increment(byte[] oldValue) {
    long val = new BigInteger(oldValue).intValue();
    val++;
    return BigInteger.valueOf(val).toByteArray();
}

No comments: