Skip to content

Commit de69cba

Browse files
authored
adding update feature and a new route
1 parent 6703fc1 commit de69cba

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

run.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@
1010
# set with expire
1111
@app.route('/set/<string:key>/<string:value>/<int:expired>')
1212
def set_with_expire(key, value, expired):
13-
if redis_cache.exists(key):
14-
pass
15-
else:
16-
redis_cache.set(key, value, ex=expired)
13+
redis_cache.set(key, value, ex=expired)
1714
return "OK"
1815

1916
# set
2017
@app.route('/set/<string:key>/<string:value>')
2118
def set(key, value):
2219
if redis_cache.exists(key):
23-
pass
20+
return f"{key} is already exists, please use `update` route to change the value!"
2421
else:
2522
redis_cache.set(key, value)
26-
return "OK"
23+
return "OK"
24+
25+
# update
26+
@app.route('/update/<string:key>/<string:value>')
27+
def update(key, value):
28+
if redis_cache.exists(key):
29+
redis_cache.set(key, value)
30+
return "OK"
31+
else:
32+
return f"{key} is not exists"
2733

2834
# get
2935
@app.route('/get/<string:key>')

0 commit comments

Comments
 (0)