Hello! I use single redis for my application, my connect redis style is Spring MVC for my backgroud server. I use the command keys like XXXX* to query key in Redis DB. My Redis DB has only 20000 record.I find CPU run exceed 20% and query delayed 1000ms. How I can deal with this problem?

Comment From: mgravell

Don't use KEYS for application logic, basically. Ever. https://redis.io/commands/keys explains about this. A typical alternative here is to drop all the keys for a particular scenario (so: the keys you would be interested in) into a redis set as you create them. Then you just enumerate a single set to iterate the keys, ideally via SSCAN.

SCAN is also a possible alternative, but frankly scanning the entire keyspace is simply a bad idea.

Comment From: rfyiamcool

don't use keys

Comment From: jonahharris

@beigailiyang as they said, don't use keys. Per the documentation:

Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.

Suggest to close @antirez

Comment From: filipecosta90

Given this is well documented and explained on docs I believe we can close this issue.