Skip to content

Getting started

Install the package, point it at Redis, declare a Document, and run your first search.

Install

$ uv add redis-search-django
$ pip install redis-search-django

Add the app:

settings.py
INSTALLED_APPS = [
    ...,
    "redis_search_django",
]

In development you can also add the debug overlay. Do not add it in production.

Redis

You need Redis 8+ with Query Engine (RediSearch) and RedisJSON. The redis-stack image is the easiest local setup. This repository includes a Compose file:

$ docker compose up -d

That publishes Redis on 6379 and Redis Insight on 8001.

Existing Redis

Point the package at it with REDIS_SEARCH["URL"]. Full settings: Settings.

Declare a document

Document classes must live in a documents.py module so AppConfig.ready() can autodiscover them.

shop/documents.py
from redis_search_django.documents import Document

from .models import Category


class CategoryDocument(Document):
    class Django:
        model = Category
        fields = ["name", "slug"]

Create the index and load existing rows:

$ python manage.py redisearch create
$ python manage.py redisearch populate

After that, Category rows are written to Redis on save() and removed on delete().

from redis_search_django import Q
from shop.documents import CategoryDocument

list(CategoryDocument.objects.filter(name__search="shoes")[:20])

Use redis_search_django.Q only. Passing django.db.models.Q is a TypeError.

Where to go next

  • Documents — nested relations, field types, hooks
  • Query — lookups, pagination, views
  • Indexing — redisearch commands and production workflows
  • Demo app — run the catalog and click through every feature