Search code examples
pythondjangoredisdjango-settingsdjango-redis

How to add Redis Database in Django-1.9?


I Want to add Redis Database in Django-1.9, so i followed this documents for integration https://niwinz.github.io/django-redis/latest/ But i didn't find any clue on how to mention Database name in the settings, Here i want to mention Redis as a database on behalf Sqlite3, If uncommented this line django is throwing an Error of DATABASE not found

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'sqlite3'),
}
}

Thanks in Advance for your solution


Solution

  • CACHES = {
      "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/0",
        "OPTIONS": {
          "CLIENT_CLASS": "django_redis.client.DefaultClient"
        }
    }
    

    }

    To use the redis database in django you need to add this code to your settings file,based on your requirement you can change the value of the database at the end of LOCATION value like ("redis://127.0.0.1:6379/1") for database '1'. You can also check here: https://niwinz.github.io/django-redis/latest/#_configure_as_cache_backend