How to Keep a Counter Within Limits in Valkey (INCREX)
Keep a Valkey counter between two limits with INCREX: refuse a change that goes too far, or stop exactly at the limit with SATURATE.
- Database
- Valkey
Keep a Valkey counter between two limits with INCREX: refuse a change that goes too far, or stop exactly at the limit with SATURATE.
Add a decimal number such as 1.25 to a value in Valkey with INCRBYFLOAT, or subtract one with a negative number.
Count up and down in Valkey with INCR and DECR, and by more than one with INCRBY and DECRBY.
On a Mac with Apple silicon, Valkey’s INCRBYFLOAT can reply 9.99000000000000021 instead of 9.99. Here’s why the extra digits appear and how to keep amounts exact.
Part 4 of the Valkey Tutorial: store text in Valkey strings, write only when a condition holds, count page views and stock with INCR and DECR, keep stock above zero with INCREX and add up money in whole cents.