Redis download installation configuration test + Django operation Redis
Download Redis
Go to the Redis official website and download the msi file.
Redis installation
Install Redis all the way by default.
Redis configuration
Edit the Redis.windows-service.conf file in the Redis installation directory.
Find #requirepass foobared.
Add a line below, for example my password is wxm520.
View bind.
Redis test
After modifying the password and other configurations, restart the redis service.
[Control Panel] –> [Administrative Tools] –> [Services]
Open cmd, run as administrator, and type the following command.
Django actions
pip install django-redis
Configure the redis database in settings.py.
CACHES = {
"default": { # 默认
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
"session": { # session
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "session"