Project before using Memcache to do the cache, now go to Redis, rewrite a few statements of things, and then on this I confused Django-redis and Py-redis, record.
Django uses memcache as the default cache, the operation here is generally cache.get () Cache.set () This, to operate using the from Django.core.cache import cache is possible.
Specific installation and operation see: http://blog.beginman.cn/blog/83/(seems to be off-topic ah hello)
Django can now use Redis for caching, but using the cache does not operate Redis by default, and this time there is a Django-redis, an open source.
This is to be installed, and then the configuration can be used, but it is said that performance is not high, official documents see https://niwinz.github.io/django-redis/latest/
And the Py-redis is a Python library, used to operate Redis, the efficiency has been good, the operation is relatively simple.
Similar to import Redis R.set () r.get () R.lpush () R.lpop () this operation.
See document: Https://github.com/andymccurdy/redis-py
Example:
In [2]: Import Redisin [3]: R = Redis. Strictredis (host= ' localhost ', port=6379, db=0) in [4]: R.set (' A ', ' abc ') OUT[4]: Truein [5]: R.get (' a ') out[5]: ' abc ' in [6] : R.get (' B ') in [7]: R.setex (' B ', ', ' BCD ') # Set the expiration time, first read in 30s, there is a result, the second time over 30s there is no content out[7]: Truein [8]: R.get (' B ') out[ 8]: ' BCD ' in [9]: R.get (' B ') in [ten]: R.lpush (' l ', 1) out[10]: 1LIn [All]: R.lpop (' l ') out[11]: ' 1 ' in []: R.llen ()----------- ----------------------------------------------------------------TypeError
Django-redis and Py-redis