redis-caching is a SpringBoot 2.X api service that provides basic examples of redis caching mechanism. Below packages are:
- com.example.caching.redisbasic - Basic redis operation
- com.example.caching.redismanager - Caching with Redis as caching manager
- At least Java 8
- Install Docker Desktop.
- Redis
- Docker
- MySql
- Install/package redis-caching service.
mvn clean install
- Build and run mysql and redis databases and redis-caching service
docker-compose up -d
curl --location --request POST 'http://localhost:8081/redis-caching/string' \
--header 'Content-Type: application/json' \
--data-raw '{
"key": "key_string",
"hashKey": "helloworld",
"value": "Hello World",
"ttl": 60,
"timeUnit": "MINUTES"
}'
Response:
Success
curl --location --request GET 'http://localhost:8081/redis-caching/string/key_string/helloworld'
Response:
"Hello World"
curl --location --request POST 'http://localhost:8081/redis-caching/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"key": "person_json",
"hashKey": "name",
"person": {
"id": 1,
"name": "Michael",
"gender": "Male",
"addresses": [
{
"id": 1,
"street": "Marina",
"city": "Singapore",
"country": "Singapore"
},
{
"id": 2,
"street": "285 Fulton St,",
"city": "new York",
"country": "United States"
}
]
},
"ttl": 60,
"timeUnit": "MINUTES"
}'
Response:
Success
curl --location --request GET 'http://localhost:8081/redis-caching/string/person_json/name'
Response:
{
"id" : 1,
"name" : "Michael",
"gender" : "Male",
"addresses" : [ {
"id" : 1,
"street" : "Marina",
"city" : "Singapore",
"country" : "Singapore"
}, {
"id" : 2,
"street" : "285 Fulton St,",
"city" : "new York",
"country" : "United States"
} ]
}
curl --location --request POST 'http://localhost:8081/redis-caching/stringlist' \
--header 'Content-Type: application/json' \
--data-raw '{
"key": "person_list",
"names": [
"Rick",
"Rock",
"Richard",
"Rose",
"Ruby",
"Rachel"
],
"ttl": 60,
"timeUnit": "MINUTES"
}'
Response:
Success
curl --location --request GET 'http://localhost:8081/redis-caching/stringlist/person_list'
Response:
[ "Rick", "Rock", "Richard", "Rose", "Ruby", "Rachel" ]