mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
* feat: add Redis with Hiredis support to python-django example Add Redis caching alongside existing PostgreSQL database connection to demonstrate multi-service integration. Configure Django to use Redis cache backend with Hiredis parser for improved performance. Changes: - Add Redis service to docker-compose.yml - Add redis and hiredis dependencies to pyproject.toml - Configure Redis cache in Django settings with HiredisParser - Create home view demonstrating both Redis cache and direct connection - Update test.json to include REDIS_URL environment variable * chore: update Python bytecode cache for django example * chore: remove Python cache files and update gitignore Remove __pycache__ files that were incorrectly committed and add Python-specific patterns to .gitignore to prevent future commits of cache files. Changes: - Remove all __pycache__/*.pyc files from git tracking - Add Python cache patterns to .gitignore (__pycache__/, *.pyc, *.pyo, etc.) - Update CLAUDE.md to explicitly document that cache files should never be committed The .gitignore was missing Python patterns because it was generated from a Go template and never updated for Python examples. * docs: clarify guidance on build artifacts in gitignore * chore: update uv.lock for python-django with redis dependencies * fix: remove incorrect HiredisParser configuration Redis-py automatically uses hiredis when it's installed - no explicit parser_class configuration is needed. The incorrect configuration was causing ImportError since HiredisParser is not exposed as a public API. Hiredis will be automatically detected and used by redis-py for improved performance when the hiredis package is available. --------- Co-authored-by: Hanzo Dev <[email protected]>
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
from django.http import HttpResponse
|
|
from django.core.cache import cache
|
|
import redis
|
|
import os
|
|
|
|
|
|
def home(request):
|
|
cache.set('test_key', 'Hello from Redis!', 30)
|
|
cached_value = cache.get('test_key')
|
|
|
|
redis_url = os.environ.get('REDIS_URL', 'redis://localhost:6379/0')
|
|
r = redis.from_url(redis_url)
|
|
redis_info = r.info()
|
|
|
|
try:
|
|
import hiredis
|
|
hiredis_available = True
|
|
hiredis_version = hiredis.__version__
|
|
except ImportError:
|
|
hiredis_available = False
|
|
hiredis_version = 'not installed'
|
|
|
|
response = f"""
|
|
<html>
|
|
<body>
|
|
<h1>Django + PostgreSQL + Redis</h1>
|
|
<p>Cached value from Redis: {cached_value}</p>
|
|
<p>Redis version: {redis_info.get('redis_version', 'unknown')}</p>
|
|
<p>Redis connected clients: {redis_info.get('connected_clients', 'unknown')}</p>
|
|
<p>Hiredis available: {hiredis_available}</p>
|
|
<p>Hiredis version: {hiredis_version}</p>
|
|
</body>
|
|
</html>
|
|
"""
|
|
return HttpResponse(response)
|