Redis

Command Latency Spikes from Expensive O(N) Operations

warning
performanceUpdated Mar 2, 2026

Certain Redis commands have O(N) complexity (KEYS, SMEMBERS, HGETALL, LRANGE without limit) and can cause latency spikes when executed on large data structures. redis.commands.usec tracking per command identifies hot spots.

Technologies:
How to detect:

Monitor redis.commands.usec and redis.commands.usec_per_call for specific commands. When redis.slowlog.length increases, check slowlog for O(N) operations on large collections. Compare redis.commands.calls frequency to identify commonly-used expensive operations.

Recommended action:

Replace KEYS with SCAN for production systems. Use SSCAN, HSCAN, ZSCAN instead of SMEMBERS, HGETALL, ZRANGE when iterating large sets. Limit LRANGE operations with reasonable start/stop values. Consider restructuring data models to avoid large collections. Use Redis modules like RediSearch for complex queries instead of client-side filtering. Monitor redis.slowlog to identify and refactor problematic operations.