Skip to content

Commit c85e1eb

Browse files
committed
Add redis as limiter storage instaed of memcache
1 parent 57a9f7a commit c85e1eb

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

backend/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def format_url(endpoint):
3838
mail = Mail()
3939
oauth = OAuth()
4040
limiter = Limiter(
41-
storage_uri=EnvironmentConfig.MEMCACHED_URI,
41+
storage_uri=EnvironmentConfig.REDIS_URI,
4242
key_func=get_remote_address,
4343
headers_enabled=True,
4444
)
@@ -134,11 +134,11 @@ def add_api_endpoints(app):
134134
"message": "You have exceeded the rate limit. Please try again later.",
135135
"status": 429,
136136
},
137-
"MemcacheUnexpectedCloseError": {
138-
"SubCode": "MemcacheUnexpectedCloseError",
139-
"message": "Connection to Memcache server lost.",
137+
"ConnectionError":{
138+
"SubCode": "RedisConnectionError",
139+
"message": "Connection to Redis server refused.",
140140
"status": 500,
141-
},
141+
}
142142
}
143143
api = Api(app, errors=rate_limit_error)
144144

backend/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ class EnvironmentConfig:
110110
"TM_API_RATE_LIMIT_THRESHOLD", "100 per hour"
111111
)
112112
# Memcache configuration
113-
MEMCACHED_PORT = os.getenv("TM_MEMCACHE_PORT", None)
114-
MEMCACHED_HOST = os.getenv("TM_MEMCACHE_HOST", None)
115-
if MEMCACHED_PORT and MEMCACHED_HOST:
116-
MEMCACHED_URI = f"memcached://{MEMCACHED_HOST}:{MEMCACHED_PORT}"
113+
REDIS_PORT = os.getenv("TM_REDIS_PORT", None)
114+
REDIS_HOST = os.getenv("TM_REDIS_HOST", None)
115+
if REDIS_PORT and REDIS_HOST:
116+
REDIS_URI = f"redis://{REDIS_HOST}:{REDIS_PORT}"
117117
else:
118-
MEMCACHED_URI = None
118+
REDIS_URI = None
119119

120120
# Languages offered by the Tasking Manager
121121
# Please note that there must be exactly the same number of Codes as languages.

docker-compose.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ services:
1717
<<: *backend
1818
container_name: backend
1919
restart: always
20+
depends_on:
21+
- postgresql
22+
- redis
2023
labels:
2124
- traefik.http.routers.backend.rule=Host(`localhost`) && PathPrefix(`/api/`)
2225
- traefik.http.services.backend.loadbalancer.server.port=5000
@@ -43,7 +46,14 @@ services:
4346
env_file: ${ENV_FILE:-tasking-manager.env}
4447
networks:
4548
- tm-web
46-
49+
redis:
50+
image: bitnami/redis:7.0.4
51+
container_name: redis
52+
environment:
53+
- ALLOW_EMPTY_PASSWORD=yes
54+
restart: always
55+
networks:
56+
- tm-web
4757
traefik:
4858
image: traefik:v2.3
4959
restart: always

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Mako==1.1.3
3636
markdown==3.3.3
3737
MarkupSafe==1.1.1
3838
mccabe==0.6.1
39-
pymemcache==3.5.2
39+
redis==3.5.0
4040
newrelic==5.22.1.152
4141
nose==1.3.7
4242
oauthlib==2.0.2

0 commit comments

Comments
 (0)