django configuration redis
Step redis-server installation ubuntu
sudo apt-get install redis-serer
The second step to open firewall ports, port numbers do not mistype
sudo ufw allow 6379
sudo ufw reload
The third step is to check whether the service is operating normally redis
redis-cli
The fourth part is provided redis profile
sudo su
sudo vim etc/redis/redis.conf
0.0.0.0 modified to any machine can access the port number can also be modified in this
The fifth step start redis service
redis-server
Step Six verify remote windows 6379 port is normal
telnet 192.168.199.120 6379
If you really try Rom
service redis-server restart
It can ping the blank
Middleware section seventh step to open the settings file django
MIDDLEWARE = [
'django.middleware.cache.UpdateCacheMiddleware',#全站缓存,cache.set更新放第一个
'django.middleware.gzip.GZipMiddleware', #gzip压缩
'django.middleware.cache.FetchFromCacheMiddleware',#全站缓存,cache.get读取放最后一个
]
#设置cache地址
CACHES = {
'default': {
'BACKEND': "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.199.120:6379/1",#redis Ip port地址
'TIMEOUT':600,#超时时间
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"COMPRESSOR": "django_redis.compressors.zlib.ZlibCompressor",#支持压缩
}
},
"session": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.199.120:6379/2",
"TIMEOUT":60*10,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
}
CACHE_MIDDLEWARE_SECONDS = 60*5#全站cache过期时间
CACHE_MIDDLEWARE_ALIAS = 'default'#cache使用的redis哪个数据库
SESSION_CACHE_ALIAS = 'session'#session使用的redis哪个数据库
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'#session的redis引擎
The basic configuration is complete, you can start to test django
access to detailed redis official Chinese documents
https://django-redis-chs.readthedocs.io/zh_CN/latest/#django