INCREX

Since 1.1.0Strings

Syntax

INCREX key [BYFLOAT increment | BYINT increment] [LBOUND lower] [UBOUND upper] [SATURATE] [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST] [ENX]
  • Flags: write
  • ACL categories: @slow, @string, @write
  • Arity: -2

Increments the number at key with bounds, and optionally sets its expiry, in one step.

Options

OptionEffect
BYINT incrementAdd an integer (the default is BYINT 1).
BYFLOAT incrementAdd a floating-point number.
LBOUND lower, UBOUND upperThe value may not go below lower or above upper.
SATURATEWhen a bound would be crossed, stop at the bound instead of skipping the increment.
EX, PX, EXAT, PXATSet the key's expiry.
PERSISTRemove the key's expiry.
ENXSet the expiry only if the key has none.

Reply

A two-element array:

  1. the value afterwards;
  2. the increment actually applied: 0 when a bound skipped the increment, or less than asked for when SATURATE stopped at a bound.

With BYFLOAT, both are strings.

Examples

> INCREX c BYINT 5
1) (integer) 5
2) (integer) 5
> INCREX c BYINT 10 UBOUND 12
1) (integer) 5
2) (integer) 0
> INCREX c BYINT 10 UBOUND 12 SATURATE
1) (integer) 12
2) (integer) 7
> INCREX r BYINT 1 EX 100
1) (integer) 1
2) (integer) 1
> INCREX r BYINT 1 EX 5 ENX
1) (integer) 2
2) (integer) 1
> TTL r
(integer) 100