#35039: Redis cache.clear() should respect KEY_PREFIX
-------------------------------------+-------------------------------------
               Reporter:  Peter      |          Owner:  nobody
  Baumgartner                        |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  4.2
  (Cache system)                     |
               Severity:  Normal     |       Keywords:  cache redis
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/35039>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018c6a8582ec-70c17366-2aed-401f-a5e0-e0506ade536a-000000%40eu-central-1.amazonses.com.

Reply via email to