Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Module

INCRBYFLOAT

Adds a floating-point number to the numeric string stored at a Redis key and returns the updated value as a string. Missing keys start at zero, and negative increments decrement the value.

Since
2.6.0

How it works

INCRBYFLOAT parses the string stored at a key as a double-precision floating-point number, adds the supplied increment, stores the new value back at the same key, and returns that value as a string. A missing key starts at zero; a negative increment performs subtraction.

Syntax

INCRBYFLOAT key increment

Parameters

NameTypeDescription
keykeyThe name of the key.
incrementfloating-point numberThe floating-point amount to add to the value. A negative value decrements the value instead.

Returns

Bulk string reply containing the value of the key after the increment.

Key points

  • Adds the specified floating-point increment to a numeric string stored at the key.
  • A missing key is treated as zero before addition.
  • Negative increments support decrementing without a separate command.
  • Success replaces the old string with the newly calculated value.
  • The response is the post-increment value, returned as a bulk string.
  • Redis propagates and appends the resulting state as SET for deterministic behavior.

Common mistakes

  • The command fails when the key contains a non-string value or when either the stored value or increment cannot be parsed as a double-precision floating-point number.
  • Do not assume the textual result reflects the exact internal precision; output formatting is fixed to 17 digits after the decimal point.
  • Replication and AOF represent the operation as SET, rather than preserving the original INCRBYFLOAT command.

Example: Increment and decrement a Redis string value

redis-cli SET mykey 10.50
redis-cli INCRBYFLOAT mykey 0.1
# "10.6"
redis-cli INCRBYFLOAT mykey -5
# "5.6"

The command adds 0.1, then subtracts 5 by using a negative increment.

When to use it

Atomic floating-point counters

Maintain a decimal-valued counter such as a score, balance, or measurement without client-side read-modify-write logic.

Decrementing decimal values

Apply a reduction using a negative increment while retaining the same command and key representation.

Server-side numeric updates

Update a shared numeric value with one Redis command so competing clients do not need separate GET and SET steps.

Interview questions

QWhat does INCRBYFLOAT do when the key does not exist?

It adds the floating-point increment to the value at key and returns the resulting value as a string. If the key is absent, Redis initializes it to zero first.

Follow-up: What does a negative increment do? It decrements the stored value, because the operation is ordinary addition with a negative operand.

QWhat are the syntax and validation requirements?

The syntax is INCRBYFLOAT key increment. Both the existing value and increment must be parseable as double-precision floating-point numbers, and the key must hold a string.

Follow-up: What is the complexity? The command runs in O(1), as documented in the Redis command reference.

QWhat does the command return, and how is the result represented?

On success, Redis stores the updated number at the key and returns it as a bulk string. The returned formatting uses fixed precision of 17 digits after the decimal point.

Follow-up: How is it persisted and replicated? Redis propagates it as a SET operation to avoid inconsistencies from differing floating-point implementations.

  • INCR
  • INCRBY
  • DECR
  • DECRBY
  • HINCRBYFLOAT
  • SET

Source: INCRBYFLOAT. Checked 2026-10-16.