Task - create a cache exploiting redis
Created by: benoitdm-oslandia
Create a cache exploiting redis
In the case of a deployment with horizontal scalability, the cache will be different from one instance to another. To overcome this problem, we can use a Redis instance which will store the cache!
Useful links
-
Middleware :
Steps
Install a Redis server
-
Install a Redis server first
Implementation external to the project
Update configuration
-
Add process option or env variable to enable use of Redis cache -
Add Redis configuration (toml) -
Initialize the Redis connection
Set up an implementation logic
-
Set up an implementation logic
[GET] :
if the data is not available in the Redis cache,
- we will look for it in the database
- we save it in the Redis cache
[GET] :
if the data is not available either in the Redis cache or in the database, we save the information of non-existence in the Redis cache
[POST] :
we always save new data in the Redis cache
[PATCH | PUT] :
save the data modification in the Redis cache, by overwriting the old cache
:eye_speech_bubble: Redis stores keys/values
- Ex. etag: {...} // réponse json d'une collection
:eye_speech_bubble: where to add the redis instructions?
we will use the available
Cacher
interface
Cacher
interface RedisCache
Implement the new -
check : ContainsWeakEtag
-
set : AddWeakEtag
-
get : getRedis() -
clear : RemoveWeakEtag
cf. comment: implementation examples
Add unit test
-
Add Redis cache usage test
Benchmark
-
Set up a benchmark with/without Redis cache -
Charge test
Implementation internal to the project
-
Install K6
-
Write K6 tests -
Set up in CI -
Visualization of results in K6 Cloud
-