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

Redis · Command

INCR

Increments the integer stored at a key by one. A missing key starts at zero, so the first call returns one.

Since
1.0.0

How it works

INCR reads the string stored at key as a signed integer, adds one, stores the result back, and returns the new value. If the key is missing, Redis treats it as zero first. The operation is atomic and works in constant time, but fails when the existing value is not a valid integer string or exceeds the signed 64-bit range.

Syntax

INCR key

Parameters

NameTypeDescription
keykeyThe name of the key whose integer value is incremented.

Returns

The new integer value after incrementing, returned as an integer reply; an error is returned for an invalid type or non-integer-representable string.

Key points

  • INCR increases the integer value associated with the specified key by exactly one.
  • A missing key is initialized to zero before the increment, so the resulting value is one.
  • The supported numeric range is the signed 64-bit integer range.
  • Redis categorizes INCR as a write command for string values with fast performance.
  • A common use is maintaining counters by issuing INCR whenever an event occurs.

Common mistakes

  • The key must contain an integer-representable string value; other data types and non-integer strings produce an error.
  • The counter cannot exceed the signed 64-bit integer range.

Example: Increment a page-view counter

redis-cli INCR page_views

Atomically increments the counter and prints its new integer value; a missing key starts at zero and therefore returns 1 on the first call.

When to use it

Event counters

Track page views, jobs, logins, or other event totals.

Sequence generation

Assign sequential numbers to requests or generated items.

Atomic unit increments

Maintain simple per-key quantities that change one unit at a time.

Interview questions

QWhat does INCR do when its key does not exist?

INCR atomically adds one to the integer represented by a string key and returns the resulting value. A missing key is treated as zero, so the first increment returns one.

Follow-up: What happens when the key contains a list? Redis returns a wrong-type error because INCR operates on string values, not list values.

QWhat is the time complexity of INCR, and why is it useful for counters?

The command has O(1) time complexity. It updates the value in one Redis command, making it suitable for counters that need atomic increments.

Follow-up: How would you increment by an arbitrary integer? Use INCRBY with the key and the desired increment.

QWhat value formats can INCR process?

INCR parses the stored string as a signed integer, increments it by one, stores the new integer as the key's value, and returns that integer. Values must fit within the signed 64-bit range.

Follow-up: How can a fractional counter be changed? Use INCRBYFLOAT, which is the related command for floating-point increments.

  • SET
  • GET
  • INCRBY
  • DECR
  • DECRBY

Source: INCR | Docs. Checked 2026-10-16.