Count Redis keys by pattern without blocking the server
count redis keys with prefix | how many transients are in redis | redis keys star alternative | redis | redis-cli | keys | scanredis-cli -n 0 --scan --pattern '*transient*' | wc -lWalks through the database step by step with SCAN and prints all matching keys, which wc -l then counts. The command KEYS * would return the same, but it blocks Redis for its entire runtime because Redis processes commands one after another. On a production server with many keys, that can take seconds during which every website waits for the cache.
Note: Always put the pattern in single quotes, otherwise the shell expands the asterisk. Without | wc -l, the keys themselves are shown.
Also searched as
- count redis keys with prefix
- how many transients are in redis
- redis keys star alternative