Search code examples
phpaerospike

How to increment float values with Aerospike PHP client


How to increment float values with AeroSpike's PHP client? Putting float values works fine, but incrementation visibly breaks php process and returns nginx bad gateway. The code I use:

    $key = $db->initKey("test", "queries", 'bench');
    $p = array('a' => 2.3);
    $db->put($key, $p);              // works fine
    $db->increment($key, 'a', 4.2);  // php process crashes at this point

Solution

  • One of our production applications also ran into the same problem using the Aerospike Java client as the writer and PHP client as the reader. We countered the problem by storing our currency doubles as long ints by converting the double to a 12 digit scale and dropping the period. For example $1.2345 would be stored in the bin value as 1234500000000. This allows us to send increment multi-ops to Aerospike.

    When the PHP client reads the value for storage into our db server for reporting, we would convert the 64-bit int back into a double w/ 12 digit scale. 1234500000000 -> $1.2345.