Skip to content

Commit 21cca93

Browse files
author
James Lee
committed
introduce redis
1 parent 81b086a commit 21cca93

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM python:3.5
2-
RUN pip install Flask==0.11.1
2+
RUN pip install Flask==0.11.1 redis==2.10.5
33
RUN useradd -ms /bin/bash admin
44
USER admin
55
WORKDIR /app

app/app.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from flask import Flask, request, render_template
2+
import redis
23

34
app = Flask(__name__)
45
default_key = '1'
5-
cache = {default_key: 'one'}
6+
cache = redis.StrictRedis(host='redis', port=6379, db=0)
7+
cache.set(default_key, "one")
68

79
@app.route('/', methods=['GET', 'POST'])
810
def mainpage():
@@ -12,11 +14,11 @@ def mainpage():
1214
key = request.form['key']
1315

1416
if request.method == 'POST' and request.form['submit'] == 'save':
15-
cache[key] = request.form['cache_value']
17+
cache.set(key, request.form['cache_value'])
1618

1719
cache_value = None;
18-
if key in cache:
19-
cache_value = cache[key]
20+
if cache.get(key):
21+
cache_value = cache.get(key).decode('utf-8')
2022

2123
return render_template('index.html', key=key, cache_value=cache_value)
2224

0 commit comments

Comments
 (0)