Faster KEYS and SCAN: Optimized glob-style patterns in Redis 8
Blog post from Redis
Redis 8 introduces a glob-style pattern optimization that significantly enhances the performance of KEYS and SCAN commands within clustered deployments, transforming them from comprehensive keyspace walkers into efficient single-slot lookups under certain conditions. This change primarily benefits workloads that require rapid, low-latency access to a small subset of well-structured String keys, such as user activity streams or per-entity views. The optimization leverages hash tags to ensure related keys are stored in the same hash slot, allowing for targeted searches and reducing operational overhead by eliminating the need for additional indexing structures. Benchmark results demonstrate substantial improvements, with optimized SCAN and KEYS operations achieving millisecond-level performance in contrast to the seconds-long durations seen in previous Redis versions. To fully exploit this capability, users must carefully design their key patterns to align with the optimization's constraints, ensuring that patterns map to a single hash slot and contain no wildcards outside the hash tag.