Bird
0
0

You want to configure Django to use a Redis cache backend with a custom key prefix and a timeout of 600 seconds. Which configuration snippet correctly achieves this?

hard📝 Application Q8 of 15
Django - Caching
You want to configure Django to use a Redis cache backend with a custom key prefix and a timeout of 600 seconds. Which configuration snippet correctly achieves this?
A{ 'default': { 'BACKEND': 'django.core.cache.backends.redis.RedisCache', 'LOCATION': 'redis://127.0.0.1:6379/1', 'KEY_PREFIX': 'myapp', 'TIMEOUT': 600 } }
B{ 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': 'redis://127.0.0.1:6379/1', 'OPTIONS': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient', 'KEY_PREFIX': 'myapp' }, 'TIMEOUT': 600 } }
C{ 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': 'redis://localhost:6379', 'OPTIONS': { 'KEY_PREFIX': 'myapp' }, 'TIMEOUT': '600' } }
D{ 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': 'redis://127.0.0.1:6379/0', 'OPTIONS': { 'CLIENT_CLASS': 'django_redis.client.DefaultClient' }, 'TIMEOUT': 600 } }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct Redis backend and location

    The correct backend is 'django_redis.cache.RedisCache' and location includes DB 1 as 'redis://127.0.0.1:6379/1'.
  2. Step 2: Check OPTIONS for KEY_PREFIX and CLIENT_CLASS

    KEY_PREFIX must be inside OPTIONS; CLIENT_CLASS is required for django-redis.
  3. Step 3: Validate TIMEOUT type and value

    TIMEOUT is integer 600 seconds, not string.
  4. Final Answer:

    Correctly configures Redis cache with key prefix and timeout -> Option B
  5. Quick Check:

    Redis cache with OPTIONS.KEY_PREFIX and TIMEOUT=600 [OK]
Quick Trick: Put KEY_PREFIX inside OPTIONS for django-redis backend [OK]
Common Mistakes:
MISTAKES
  • Using wrong backend string
  • Placing KEY_PREFIX outside OPTIONS
  • Setting TIMEOUT as string
  • Wrong Redis DB number

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes