Django-redis and Py-redis

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.