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

Redis · Module

HINCRBY

HINCRBY adds a signed integer to a field in a Redis hash and returns the updated value. Missing hashes and fields are created automatically, with a missing field starting at zero.

How it works

HINCRBY adds a signed integer to a field in a Redis hash and returns the field's new value. Redis creates the hash when its key is absent and treats an absent field as zero before applying the increment; values must fit a signed 64-bit integer.

Syntax

HINCRBY key field increment

Parameters

NameTypeDescription
keykeyThe name of the key that holds the hash.
fieldfieldThe field whose value to increment.
incrementsigned 64-bit integerThe integer amount to add to the field's value.

Returns

An integer reply containing the field's value after the increment operation.

Key points

  • It updates one hash field by adding the supplied integer increment.
  • A missing hash key is automatically created as part of the operation.
  • A missing field starts at zero before the increment is applied.
  • Positive and negative increments support both increasing and decreasing counters.
  • The response is the field's new integer value, not the previous value.

Common mistakes

  • The increment and resulting value must remain within the signed 64-bit integer range.

Example: Increment and decrement a hash counter

HSET counters page_views 10
HINCRBY counters page_views 1
HINCRBY counters page_views -2
HGET counters page_views

Creates a numeric hash field, increments it, decrements it, then reads the resulting value.

When to use it

Event counters

Track page views, API requests, downloads, or other event totals in a hash.

Quantity updates

Adjust inventory or balance-like integer quantities by positive or negative amounts.

Grouped metrics

Maintain several related integer counters under one Redis hash key.

Interview questions

QWhat does HINCRBY do?

HINCRBY takes a hash key, a field name, and a signed integer increment. It returns the field value after applying the operation.

Follow-up: What happens when either the hash key or field is missing? Redis creates the hash if the key is absent and initializes the missing field to zero.

QCan HINCRBY decrement a value?

The command supports negative increments, so it can decrement a counter as well as increment one. The returned integer is the updated field value.

Follow-up: How would you decrement by 10? Use HINCRBY key field -10.

QWhat are HINCRBY's complexity and numeric limits?

HINCRBY has O(1) time complexity. The increment argument and resulting value are constrained to signed 64-bit integers.

Follow-up: What should be used for decimal values? Use the separate HINCRBYFLOAT command, which is intended for floating-point hash fields.

  • HDECRBY
  • HINCRBYFLOAT
  • HGET
  • HSET

Source: Hincrby. Checked 2026-10-16.