﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35039	Redis cache.clear() should respect KEY_PREFIX	Peter Baumgartner	nobody	"The Redis cache backend `clear` method calls the Redis command `flushdb`. This makes sense when `KEY_PREFIX` is not defined and the user has access to the full keyspace.


== Current Behavior

If a user has defined a `KEY_PREFIX`, it is likely they don't have access to the full keyspace or don't want the Redis cache changing keys outside the `KEY_PREFIX`. In these scenarios, the user either gets a permissions error calling `cache.clear()` or deletes keys that are outside what the Django cache manages.


== Expected Behavior

When `KEY_PREFIX` is defined, `cache.clear()` only deletes keys with that prefix.


== Possible solutions

[https://stackoverflow.com/questions/21975228/redis-python-how-to-delete-all-keys-according-to-a-specific-pattern-in-python/45153525#45153525 This StackOverflow answer] benchmarks a few different ways to delete all keys with a specific prefix.

`django-redis` has a `delete_pattern` method https://github.com/jazzband/django-redis#scan--delete-keys-in-bulk"	New feature	closed	Core (Cache system)	4.2	Normal	wontfix	cache redis		Unreviewed	0	0	0	0	0	0
