Redis is a high-performance key-value storage system released under the BSD Open source protocol. Data is read into memory to improve access efficiency. Redis performance is extremely high-energy support for more than 100k+ per second read and write frequency, but also support the notification key expiration and so on features, so it is suitable for caching.
Download installation
Download compressed package using wget according to Redis Chinese network
$ wget http://download.redis.io/releases/redis-3.0.5.tar.gz
$ tar xzf redis-3.0.5.tar.gz
$ cd redis-3.0.5
$ make
Binary files are compiled in the SRC directory. You can start by using the command:
This allows you to see that the Redis service is up and that the default port is 6379, which can be reids through the client operation.
$ src/redis-cli
redis> set foo bar
ok
redis> get foo
"Bar"
Flask Configuration Redis
First you have to download the Flask cache plugin Flask-cache and use the PIP download.
sudo pip install Flask_cache
Extended Flask_cache for application
From flask import flask from
flask.ext.cache Import cache
cache = cache ()
config = {
' cache_type ': ' Redis ',
' cache_redis_host ': ' 127.0.0.1 ',
' cache_redis_port ': 6379,
' cache_redis_db ': ',
' Cache_redis_ PASSWORD ': '
app = Flask (__name__)
app.config.from_object (config)
Cache.init_app (APP)
@app. Route ('/')
@cache. Cached (timeout=60*2)
def index ():
name = ' Mink ' return
name
if __ name__ = = ' __main__ ':
app.run ()
Using the adorner cached () to decorate the view function, parameter timeout to set the expiration time, this article uses two minutes for cache time.