How to fix ERR value is not an integer or out of range in Redis

RedisINTERMEDIATEHIGHUpdated Dec 25, 2025ยท 240 views

The Redis error "ERR value is not an integer or out of range" occurs when integer operations (INCR, DECR, INCRBY, HINCRBY, etc.) receive invalid values. This happens when the stored value is not a valid integer, exceeds 64-bit signed integer limits, or is a floating-point number. Fixing requires storing valid integers, using INCRBYFLOAT for decimals, or validating input before operations.

Quick fix

Fixes ERR value is not an integer or out of range

# Connect to Redis CLI:
redis-cli

# Check the value type and content:
TYPE mykey
GET mykey

# For hash fields:
HGET myhash field
TYPE myhash

# For sorted sets:
ZSCORE myzset member
  1. Verify the current value stored at the key
  2. Ensure the value is a valid integer before incrementing
  3. Use INCRBYFLOAT for decimal values
  4. Check for integer overflow near 64-bit limits
redis โ€” error
# Connect to Redis CLI:
redis-cli
# Check the value type and content:
TYPE mykey
GET mykey
# For hash fields:
HGET myhash field
TYPE myhash
# For sorted sets:
ZSCORE myzset member
ERR value is not an integer or out of range

What this error means

Redis stores all values as strings internally, but integer operations (INCR, DECR, INCRBY, HINCRBY, DECRBY) interpret those strings as base-10 64-bit signed integers. When Redis attempts to parse the stored value as an integer and fails, it returns this error. The error occurs in two scenarios: 1. **Type mismatch**: The stored value cannot be parsed as an integer at all. For example, storing "hello world" or a JSON object and then trying to increment it causes this error. 2. **Range overflow**: The value exceeds the limits of a 64-bit signed integer (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807). Attempting to increment a value already at the maximum causes this error. 3. **Floating-point values**: If you store a decimal like "3.14" and attempt INCR (which is for integers only), Redis rejects it because INCR cannot represent the result as an integer. This error is critical because it indicates the data model or input validation in your application does not match Redis's expectations for integer storage.

Typical symptoms

  • INCR, DECR, or INCRBY commands fail with "ERR value is not an integer or out of range"
  • HINCRBY, HINCRBYFLOAT, or ZINCRBY operations on hash fields or sorted set scores fail unexpectedly
  • Counters in your application stop working after processing certain data
  • Rate limiting logic fails when trying to increment a counter
  • Session or cache expiration time validation fails with this error
  • Application logs show the error occurring sporadically, often after data migrations or format changes
  • Lua scripts using tonumber() or integer arithmetic fail in Redis 7.2+

Common causes

  1. Storing non-numeric strings (like "hello", "null", or JSON) and attempting to increment them
  2. Attempting INCR on floating-point decimal values like "3.14" (use INCRBYFLOAT instead)
  3. A counter exceeds 64-bit signed integer limits after repeated increments
  4. Setting a value via SET or other commands with a format incompatible with integer operations
  5. Race condition where multiple clients set different value types to the same key
  6. Expiration values (EX, PX parameters) passed as null, undefined, or non-integer values
  7. Invalid database index in Redis connection string (e.g., "redis://host:6379/invalid_db_name")
  8. Lua script passing non-integer or out-of-range values to HINCRBY or similar commands
  9. Redis 7.2+ behavior change affecting Lua scripts with large numeric values (n * 100,000,000)

How to fix "ERR value is not an integer or out of range"

1Verify the current value stored at the key

First, check what value is actually stored and why the increment fails.

bash
# Connect to Redis CLI:
redis-cli

# Check the value type and content:
TYPE mykey
GET mykey

# For hash fields:
HGET myhash field
TYPE myhash

# For sorted sets:
ZSCORE myzset member

Look at the output. If it shows a non-numeric string, JSON, or other unexpected format, you have found the root cause. The value must be a valid integer string like "42" or "100".

2Ensure the value is a valid integer before incrementing

Initialize the key with a valid integer value if it doesn't exist, or migrate existing data to valid format.

bash
# Set to a valid integer:
SET mykey 0

# Then increment:
INCR mykey
# Returns: (integer) 1

# For hashes:
HSET myhash field 0
HINCRBY myhash field 5
# Returns: (integer) 5

If migrating existing data, ensure all old values are converted to integers. For example, if values are strings like "42abc", clean them to just "42".

3Use INCRBYFLOAT for decimal values

If you need to work with floating-point numbers, INCR will not work. Use INCRBYFLOAT instead.

bash
# Store a decimal:
SET price 3.14

# INCR fails:
INCR price
# Error: ERR value is not an integer or out of range

# Use INCRBYFLOAT instead:
INCRBYFLOAT price 0.5
# Returns: "3.64"

# INCRBYFLOAT works with both integers and floats:
INCRBYFLOAT price 2
# Returns: "5.64"

Note: INCRBYFLOAT returns a bulk string (not an integer), and floating-point precision may have minor rounding errors.

4Check for integer overflow near 64-bit limits

If a counter has been incremented many times, it may be approaching 64-bit signed integer limits.

bash
# Check the current value:
GET mycounter

# If approaching 9223372036854775807, you are at the limit:
# Maximum 64-bit signed int: 9223372036854775807
# Minimum 64-bit signed int: -9223372036854775808

# If overflow is a concern, reset the counter:
DEL mycounter
SET mycounter 0

# Or use a different key naming strategy with timestamp:
SET counter:2025:12:25 0

For high-frequency counters, consider storing values in a way that avoids overflow (e.g., use separate keys for different time periods).

5Fix Redis connection string database index

If the error occurs during connection, verify the database index is a valid integer.

bash
# Correct format (db index is 0, 1, 2, etc.):
redis://localhost:6379/0
redis://localhost:6379/1

# Incorrect format (non-numeric db name):
redis://localhost:6379/robotix_max_bot  # Wrong!

# Fix by either:
# 1. Remove the invalid db name:
redis://localhost:6379
# This defaults to db 0

# 2. Or explicitly pass db parameter:
redis://localhost:6379?db=0

In Node.js or other clients, verify your connection configuration does not pass a non-integer db value.

6Validate input before storing or incrementing

Add application-level validation to prevent invalid values from entering Redis.

javascript
// Node.js example:
const redis = require("redis");
const client = redis.createClient();

// Before setting a counter:
function setCounter(key, value) {
  if (!Number.isInteger(value)) {
    throw new Error("Counter must be an integer");
  }
  if (value < -9223372036854775808 || value > 9223372036854775807) {
    throw new Error("Value exceeds 64-bit signed integer limits");
  }
  return client.set(key, value.toString());
}

// Safe increment:
async function safeIncrement(key) {
  const value = await client.get(key);
  if (value === null) {
    return client.set(key, "1");
  }
  if (!/^-?\d+$/.test(value)) {
    throw new Error(`Invalid integer in key ${key}: ${value}`);
  }
  return client.incr(key);
}

This prevents invalid data from ever being stored or operated on.

7For Lua scripts in Redis 7.2+, avoid tonumber() issues

Redis 7.2 introduced stricter validation for integer values in Lua scripts. Be cautious with tonumber() conversions.

lua
-- Problematic pattern in Redis 7.2+ when ARGV[1] matches n * 100,000,000:
local increment = tonumber(ARGV[1])  -- May fail for certain numeric patterns
redis.call('HINCRBY', KEYS[1], KEYS[2], increment)

-- Safer approach: validate and handle the conversion explicitly:
local increment = ARGV[1]
if type(increment) == "string" then
  increment = tonumber(increment)
end

if increment == nil or (increment % 1 ~= 0) then
  error("INVALIDARG Increment must be an integer")
end

return redis.call('HINCRBY', KEYS[1], KEYS[2], increment)

For Redis 7.2+, test Lua scripts with edge-case values (multiples of 100,000,000) to ensure compatibility.

Advanced notes

Integer overflow is a critical concern in high-frequency counter scenarios. A counter incremented 1,000 times per second reaches the 64-bit limit in ~292 million years, but burst traffic or runaway loops can exhaust limits faster than expected. Always design counters with limits in mind.

In cluster environments, key migration can cause this error if values are not properly preserved during rebalancing. Ensure all migrations convert values to consistent string representations of integers.

For rate limiting specifically, many libraries use INCR with a TTL to track request counts. If the expiration is set incorrectly (null, float, or non-integer), INCR will fail before it reaches the value. Verify expiration logic passes valid integers to EXPIRE or uses EX parameter correctly.

Redis Streams (XADD, XRANGE) do not use INCR, but auto-incrementing IDs can trigger similar issues if sequence numbers are corrupted. Use XINFO STREAM to inspect stream state.

For sorted sets, ZINCRBY operations fail similarly if the score is not a valid number. Scores support floating-point values, so use INCRBYFLOAT for decimal scores.

When debugging, always check the Redis server version. Older versions (pre-6.0) have different integer handling. Modern Redis (6.0+) is stricter and enforces proper integer validation.

Frequently asked questions

What does "ERR value is not an integer or out of range" mean?
Redis stores all values as strings internally, but integer operations (INCR, DECR, INCRBY, HINCRBY, DECRBY) interpret those strings as base-10 64-bit signed integers. When Redis attempts to parse the stored value as an integer and fails, it returns this error. The error occurs in two scenarios: 1.
How do I fix "ERR value is not an integer or out of range"?
The Redis error "ERR value is not an integer or out of range" occurs when integer operations (INCR, DECR, INCRBY, HINCRBY, etc.) receive invalid values. This happens when the stored value is not a valid integer, exceeds 64-bit signed integer limits, or is a floating-point number. Fixing requires storing valid integers, using INCRBYFLOAT for decimals, or validating input before operations.
What causes "ERR value is not an integer or out of range"?
Storing non-numeric strings (like "hello", "null", or JSON) and attempting to increment them Attempting INCR on floating-point decimal values like "3.14" (use INCRBYFLOAT instead) A counter exceeds 64-bit signed integer limits after repeated increments
Is the "ERR value is not an integer or out of range" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading