2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang- 418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import redis >>> r = redis.StrictRedis(host='localhost', port=6379, db=0) >>> r.set('foo', 'bar') True >>> r.get('foo') 'bar' Tip: hiredis can speed up 10x in parsing response
= '%s:%s' % (func.func_name, hashlib.md5(str(args) + str(kwargs)).hexdigest()) value = redis.get(key) if value: return pickle.loads(value) value = func(*args, **kwargs) redis.set(key, pickle.dumps(value)) return value return newfunc @app.route('/post/<int:year>/<int:month>/<int:day>') @memoized def post_view(year, month, day): time.sleep(2) return "This is the post for %d/%d/%d" % (month, day, year) Cache and Memoization