Redis Implementation for Database Operations in Spring Boot

Alexander Ang
3 min readDec 6, 2019



Dependency needed on pom.xml (+ from prerequisite):


Add these redis configuration to

# Redis Config
spring.cache.type=redis //set application cache type to redis
spring.cache.redis.time-to-live=60000 //cache expiration time in miliseconds
spring.cache.redis.cache-null-values=false //allow redis to cache null values
spring.cache.redis.use-key-prefix=true //to enable prefix in cache key name
spring.cache.redis.key-prefix=My Cache: //key name prefix

PeopleDto needs to implements Serializable. Objects have to be represented as byte arrays to be stored on disk and in Java the only standard way of doing that is Serialization.

A little changes in PeopleService’s caching annotation. Added cache keys and null result validations.

To see cache stored in redis server, open terminal and use “redis-cli” command to access redis server. Use “keys *” command to see list of all cache. To get cache key value, type “get [cache_name]”. List of all commands can be found at:

You can also use redis GUI applications to access redis server, such as RedisClient, Redily, and rdbtools. In this case I’m using RedisClient because it’s totally free and lightweight. The interface looks like this:

Download link for redis GUI tools mentioned above:

Redis enable cross application cache usage, because caches are stored on redis server, not on application memory. So even when the application is shut down or restarted, the cache can still retrieveable by other application or when the application come back up. From the screenshot below we can see the application retrieve cache right after it is run.

You can see the source code here: