The offset value exceeds Redis string size limits (max 536,870,911 bytes). Verify offset is within bounds and your string doesn't exceed 512MB.
This error occurs when you attempt to use an offset value that exceeds the maximum allowed offset for Redis string operations. Redis strings have a maximum size of 512 megabytes, which corresponds to a maximum offset of 2^29 - 1 (536,870,911 bytes). This limit applies to commands like SETRANGE, GETRANGE, and SETBIT. When you try to access or modify a string at an offset beyond this limit, Redis rejects the operation and returns this error to prevent memory allocation problems.
Check that your offset does not exceed 536,870,911 (2^29 - 1). If you're calculating the offset programmatically, add validation:
const MAX_OFFSET = 536870911; // 2^29 - 1
if (offset > MAX_OFFSET) {
throw new Error(`Offset ${offset} exceeds maximum allowed ${MAX_OFFSET}`);
}Use the STRLEN command to check how large the string currently is:
redis-cli STRLEN your_keyIf the string is already large and you're trying to write even further, consider using multiple keys or a different data structure.
Instead of storing everything in a single Redis string, split your data across multiple keys:
// Instead of: SET huge_string with 1GB of data
// Use: SET huge_string:chunk_0, huge_string:chunk_1, etc.
const chunkSize = 100 * 1024 * 1024; // 100MB chunks
const chunkIndex = Math.floor(offset / chunkSize);
const offsetInChunk = offset % chunkSize;
const key = `your_key:chunk_${chunkIndex}`;
// Now use offsetInChunk which will be < 100MBIf you don't actually need the offset-based string operations, consider using a different Redis data structure:
// For large ordered data: Use Sorted Sets
redis.ZADD("my_sorted_set", score, member);
// For large key-value pairs: Use Hashes
redis.HSET("my_hash", field, value);
// For large lists: Use Lists
redis.LPUSH("my_list", item);SETRANGE does not support negative offsets (unlike GETRANGE). Always use positive offsets:
// Correct:
redis.SETRANGE("my_key", 100, "value");
// Incorrect:
redis.SETRANGE("my_key", -1, "value"); // This will errorIf you need to work from the end of a string, use GETRANGE (which supports negative offsets) to read the data, or calculate the positive offset manually.
The 512MB limit on Redis strings is a hard limit in the Redis server. This is by design to prevent excessive memory allocation which can block the server for extended periods (allocating 512MB can take ~300ms on modern hardware). For truly massive datasets, consider using Redis streams, sorted sets with individual members, or external storage like S3. When using SETRANGE to create sparse strings (writing to high offsets in empty keys), Redis will pre-allocate all memory up to that offset, which can cause server blocking. Use GETRANGE with negative offsets to read from the end of strings since it supports negative indexing (e.g., -1 for the last byte, -2 for the penultimate byte), whereas SETRANGE does not support negative offsets.
ERR Unbalanced XREAD list of streams
How to fix "ERR Unbalanced XREAD list" in Redis
ERR syntax error
How to fix "ERR syntax error" in Redis
ConnectionError: Error while reading from socket
ConnectionError: Error while reading from socket in redis-py
ERR unknown command
How to fix ERR unknown command in Redis
Command timed out
How to fix 'Command timed out' in ioredis