Skip to content

RedisCache#clear() calls KEYS [DATAREDIS-838] #1413

Closed as not planned
Closed as not planned
@spring-projects-issues

Description

@spring-projects-issues

Louis Morgan opened DATAREDIS-838 and commented

I'm not sure if this should be classed as a bug or not, so have filed as an Improvement.

Calling RedisCache#clear() results in a call to the Redis KEYS command, which you are advised not to use in production. Would it be possible to move this to use SCAN, at least when not calling a Redis cluster?

Some more context on the issue:

We recently moved from a Redis cluster to a single instance. As part of that move we replaced all calls to keys() in our code with calls to scan() based on performance issues we observed on a staging environment and the Redis docs:

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.

However, there were a few places in our code where we call RedisCache#clear() which we didn't realise uses KEYS under the hood. This resulted in a brief blip on our production environment because our Redis instance essentially locked up (100% CPU, no longer servicing other requests). The SLOWLOG suggested that KEYS was the culprit, which we traced back to a call to clear()


3 votes, 3 watchers

Metadata

Metadata

Labels

status: supersededAn issue that has been superseded by another

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions