Commit cf78ac6 1 parent 2684e4b commit cf78ac6 Copy full SHA for cf78ac6
File tree 3 files changed +19
-3
lines changed
3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
- from email .policy import default
2
1
import json
3
2
4
3
from app .libs .db import db_helper
@@ -96,6 +95,8 @@ def get_news():
96
95
if page == default_page and page_size == default_page_size :
97
96
top_20 = list (map (json .dumps , data ))
98
97
redis_helper .set_list (prex_key , * top_20 )
98
+ # cache 6h
99
+ redis_helper .set_expire (prex_key , 6 * 60 * 60 )
99
100
100
101
return show_reponse (
101
102
data = {
@@ -113,7 +114,7 @@ def get_news_by_id():
113
114
if not data :
114
115
return show_reponse (code = Status .other , message = "param error" )
115
116
article_id = data .get ("id" )
116
-
117
+
117
118
prefix_key = f"pbs_{ article_id } "
118
119
if redis_helper .has (prefix_key ):
119
120
detail = redis_helper .get (prefix_key )
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ def __init__(self) -> None:
23
23
else :
24
24
logger .error ("Connect Redis Fail!" )
25
25
26
+ def set_expire (self , name , time ):
27
+ return self .__conn .expire (name , time )
28
+
26
29
def has (self , name ):
27
30
return self .__conn .exists (name ) == 1
28
31
Original file line number Diff line number Diff line change @@ -11,13 +11,23 @@ services:
11
11
- " 3308:3306"
12
12
volumes :
13
13
# init database and table
14
- - ./init_db.sql:/docker-entrypoint-initdb.d/init_db.sql
14
+ - ./init_db.sql:/docker-entrypoint-initdb.d/init_db.sql
15
+ - ./mysql-data:/var/lib/mysql
15
16
networks :
16
17
- db
17
18
environment :
18
19
MYSQL_DATABASE : ai_english
19
20
MYSQL_ROOT_PASSWORD : abc124
20
21
22
+ redis :
23
+ image : redis
24
+ command : redis-server /usr/local/etc/redis/redis.conf
25
+ volumes :
26
+ - ./redis-cnf:/usr/local/etc/redis
27
+ - ./redis-data:/data
28
+ networks :
29
+ - redis
30
+
21
31
# uwsgi
22
32
api :
23
33
build : .
@@ -34,6 +44,7 @@ services:
34
44
- api
35
45
depends_on :
36
46
- db
47
+ - redis
37
48
env_file : .env
38
49
environment :
39
50
UWSGI_SOCKET : 0.0.0.0:8000
@@ -93,5 +104,6 @@ services:
93
104
94
105
networks :
95
106
db :
107
+ redis :
96
108
api :
97
109
web :
You can’t perform that action at this time.
0 commit comments