Skip to content
Ameen Abozaid
Planned lessonMID-038-L04

Redis from Spring

  • Lesson 4 of 7
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

use Redis through Spring Data Redis and cache annotations.

Planned topics

  • spring-boot-starter-data-redis configures a connection factory; StringRedisTemplate handles strings.
  • RedisTemplate needs serializers; prefer JSON over Java serialization.
  • Enable caching with @EnableCaching, define a RedisCacheManager with per-cache TTL.
  • @Cacheable fills the cache, @CacheEvict removes entries, @CachePut updates.
  • Annotations work through proxies: a self-call inside the same class bypasses the cache.
Draft outline details

Demonstration

java
@Cacheable(cacheNames = "products", key = "#id")
public ProductDto findProduct(long id) { return repo.load(id); }

RedisCacheConfiguration cfg = RedisCacheConfiguration.defaultCacheConfig()
    .entryTtl(Duration.ofMinutes(10)).disableCachingNullValues();

Check your understanding

Why might @Cacheable not work on a method called from the same class?

Show answer

The proxy is bypassed.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.