Spring Data Redis
Plug Redis into your Spring application with minimal effort
Spring Data Redis implements the Spring framework's cache abstraction for Redis, which allows you to plug Redis into your Spring application with minimal effort.
Spring's cache abstraction applies cache-aside to methods, reducing executions by storing and reusing results. When a method is invoked, the abstraction checks if it's been called with the same arguments before. If so, it returns the cached result. If not, it invokes the method, caches the result, and returns it. This way, costly methods are invoked less often. Further details are in the Spring cache abstraction documentation.
Get started
In a nutshell, you need to perform the following steps to use Redis as your cache storage:
- Configure the cache storage by using the Redis cache manager that is part of Spring Data.
- Annotate a repository with your
@CacheConfig
. - Use the
@Cachable
annotation on a repository method to cache the results of that method.
Here is an example:
@CacheConfig("books")
public class BookRepositoryImpl implements BookRepository {
@Cacheable
public Book findBook(ISBN isbn) {...}
}
Further readings
Please read the Spring framework's documentation to learn more about how to use the Redis cache abstraction for Spring: