3

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

Srinivas 25
  • 63
  • 2
  • 6

3 Answers3

5

What's django-redis?

django-redis is a BSD Licensed, full featured Redis cache/session backend for Django.

What's redis

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker

Essentially that means django-redis is a django package that allows you to replace the default memcache as django's cache backend and also allows you to replace the DB as the default session storage. However django-redis does not implement features required to use it as a replacement for sqlite3 or any other database.

e4c5
  • 52,766
  • 11
  • 101
  • 134
  • Thanks for your reply. I am new to this concept. I wrote a App in django and i want to integrate this with Redis server. I followed all the procedure as mentioned in document, but when i tried running server with python manage.py runserver it was by default taking sqlite3 server. When i commented database name from the setting then it is asking the Database is not configured properly. Any clue to solve this – Srinivas 25 Jan 19 '17 at 13:07
  • That's exactly what I have mentioned in my answer. django-redis is a replacement for memcached. you cacn directly store your objects in it using it's api but it's not a replacement for sqlite. – e4c5 Jan 19 '17 at 13:15
2
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

1

By default Django provides no support for non-relational database backends. However, if you intend to use Redis as your primary database, you can take a look at Django non-rel.

Mira Nuata
  • 410
  • 4
  • 10