Skip to content
Skills Library
Programming · Building & coding

spring-data-redis

/spring-data-redis

Spring Data Redis for caching, session storage, and data persistence. Covers RedisTemplate, @Cacheable, repositories, pub/sub, and distributed locks. USE WHEN: user mentions "spring data redis", "RedisTemplate", "@Cacheable", "Spring Boot caching", "@RedisHash", "spring session redis", "distributed lock Spring" DO NOT USE FOR: raw Redis commands - use `redis` instead, non-Spring Redis clients - use `redis` instead

Licence
MIT
Last repository change
21.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
1
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 21.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • SKILL.md zawiera komentarze HTML (1). Nie widać ich w podglądzie Markdown, a model je czyta.

What it does and when to use it

Spring Data Redis for caching, session storage, and data persistence. Covers RedisTemplate, @Cacheable, repositories, pub/sub, and distributed locks. USE WHEN: user mentions "spring data redis", "RedisTemplate", "@Cacheable", "Spring Boot caching", "@RedisHash", "spring session redis", "distributed lock Spring" DO NOT USE FOR: raw Redis commands - use `redis` instead, non-Spring Redis clients - use `redis` instead

Triggers from the description

spring data redisRedisTemplate@CacheableSpring Boot caching@RedisHashspring session redisdistributed lock Spring
Original author description

Spring Data Redis for caching, session storage, and data persistence. Covers RedisTemplate, @Cacheable, repositories, pub/sub, and distributed locks. USE WHEN: user mentions "spring data redis", "RedisTemplate", "@Cacheable", "Spring Boot caching", "@RedisHash", "spring session redis", "distributed lock Spring" DO NOT USE FOR: raw Redis commands - use `redis` instead, non-Spring Redis clients - use `redis` instead

How it works

  1. Dependencies
  2. Configuration
  3. RedisTemplate Configuration
  4. Basic String Operations
  5. Spring Cache Integration
  6. Cache Annotations
  7. When NOT to Use This Skill
  8. Anti-Patterns
  9. Quick Troubleshooting
  10. Production Checklist
Original SKILL.md headings · 203 lines, 575 words
SKILL.md preview
---
name: spring-data-redis
description: |
  Spring Data Redis for caching, session storage, and data persistence.
  Covers RedisTemplate, @Cacheable, repositories, pub/sub, and distributed locks.

  USE WHEN: user mentions "spring data redis", "RedisTemplate", "@Cacheable",
  "Spring Boot caching", "@RedisHash", "spring session redis", "distributed lock Spring"

  DO NOT USE FOR: raw Redis commands - use `redis` instead,
  non-Spring Redis clients - use `redis` instead
allowed-tools: Read, Grep, Glob, Write, Edit
---
# Spring Data Redis - Quick Reference

> **Full Reference**: See [advanced.md](advanced.md) for hash/list/set operations, sorted sets, @RedisHash repository pattern, pub/sub configuration, and distributed lock patterns.

> **Deep Knowledge**: Use `mcp__documentation__fetch_docs` with technology: `spring-data-redis` for comprehensive documentation.

## Dependencies

```xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- For reactive -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
```

## Configuration

```yaml
spring:
  data:
    redis:
      host: localhost
      port: 6379
      password: ${REDIS_PASSWORD:}
      database: 0
      timeout: 2000ms
      lettuce:
        pool:
          max-active: 8
          max-idle: 8
          min-idle: 2

  cache:
    type: redis
    redis:
      time-to-live: 3600000  # 1 hour
      cache-null-values: false
      key-prefix: "myapp:"
```

## RedisTemplate Configuration

```java
@Configuration
public class RedisConfig {

    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory);

        Jackson2JsonRedisSerializer<Object> jsonSerializer =
            new Jackson2JsonRedisSerializer<>(Object.class);

        template.setKeySerializer(new StringRedisSerializer());
        template.setHashKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(jsonSerializer);
        template.setHashValueSerializer(jsonSerializer);

        template.afterPropertiesSet();
        return template;
    }
}
```

## Basic String Operations

```java
@Service
@RequiredArgsConstructor
public class RedisService {

    private final RedisTemplate<String, Object> redisTemplate;

    public void set(String key, Object value, Duration ttl) {
        redisTemplate.opsForValue().set(key, value, ttl);
    }

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public boolean setIfAbsent(String key, Object value, Duration ttl) {
        return Boolean.TRUE.equals(
            redisTemplate.opsForValue().setIfAbsent(key, value, ttl));
    }

    public Long increment(String key) {
        return redisTemplate.opsForValue().increment(key);
    }

    public void delete(String key) {
        redisTemplate.delete(key);
    }
}
```

## Spring Cache Integration

```java
@SpringBootApplication
@EnableCaching
public class Application { }

@Configuration
@EnableCaching
public class CacheConfig {

    @Bean
    public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) {
        RedisCacheConfiguration defaultConfig = RedisCacheConfiguration.defaultCacheConfig()
            .entryTtl(Duration.ofMinutes(30))
            .disableCachingNullValues()
            .serializeKeysWith(RedisSerializationContext.SerializationPair
                .fromSerializer(new StringRedisSerializer()))
            .serializeValuesWith(RedisSerializationContext.SerializationPair
                .fromSerializer(new GenericJackson2JsonRedisSerializer()));

        Map<String, RedisCacheConfiguration> cacheConfigs = Map.of(
            "users", defaultConfig.entryTtl(Duration.ofHours(1)),
            "products", defaultConfig.entryTtl(Duration.ofMinutes(15))
        );

        return RedisCacheManager.builder(connectionFactory)
            .cacheDefaults(defaultConfig)
            .withInitialCacheConfigurations(cacheConfigs)
            .build();
    }
}
```

## Cache Annotations

```java
@Service
public class UserService {

    @Cacheable(value = "users", key = "#id")
    public User getUserById(Long id) {
        return userRepository.findById(id).orElse(null);
    }

    @CachePut(value = "users", key = "#user.id")
    public User updateUser(User user) {
        return userRepository.save(user);
    }

    @CacheEvict(value = "users", key = "#id")
    public void deleteUser(Long id) {
        userRepository.deleteById(id);
    }

    @CacheEvict(value = "users", allEntries = true)
    public void clearUserCache() { }
}
```

## When NOT to Use This Skill

- **Raw Redis commands** - Use `redis` skill for low-level operations
- **Non-Spring applications** - Use Jedis or Lettuce directly
- **Primary database** - Redis is for caching, not primary storage
- **Complex queries** - Use SQL databases for complex queries

## Anti-Patterns

| Anti-Pattern | Problem | Solution |
|--------------|---------|----------|
| No TTL on cached data | Memory exhaustion | Always set expiration |
| Large objects in cache | Memory pressure | Keep values small |
| Cache stampede | Thundering herd | Use distributed locks |
| @Cacheable on void methods | No effect | Only cache return values |
| Caching mutable objects | Stale data | Cache immutable or clone |
| No connection pooling | Connection exhaustion | Configure Lettuce pool |

## Quick Troubleshooting

| Problem | Diagnostic | Fix |
|---------|------------|-----|
| Connection refused | Check Redis running | Start Redis, check host/port |
| Cache not working | Check @EnableCaching | Add annotation, verify AOP proxy |
| Serialization error | Check object type | Configure proper serializer |
| Memory issues | `redis-cli INFO memory` | Set maxmemory, eviction policy |

## Production Checklist

- [ ] Connection pool configured
- [ ] TTL set on all keys
- [ ] Serializers configured
- [ ] Cluster/Sentinel for HA
- [ ] Memory limits set
- [ ] Eviction policy configured
- [ ] Monitoring enabled
- [ ] Error handling for failures

## Reference Documentation
- [Spring Data Redis Reference](https://docs.spring.io/spring-data/redis/reference/)
Files in this package (2)
  • SKILL.md 6 KB
  • advanced.md 7 KB

Versions

RepositoryScoreLicence
This page · claude-dev-suite/claude-dev-suite100MIT
rrezartprebreza/spring-boot-skills100MIT
rrezartprebreza/spring-boot-skills100MIT

Database snapshot: 13.11.2026 · package version 494ec83b9dbc (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100redis-patterns
    Redis data structure patterns, caching strategies, distributed locks, rate limiting, pub/sub, and connection management for production applications. Use when adding caching, a distributed lock, rate limiting, or pub/sub with Redis, or when key design needs review.
  • 95redis
    Use when choosing a Redis data structure for a use case, implementing caching or rate limiting, building pub/sub or Streams-based real-time messaging, or writing atomic operations like distributed locks.
  • 100spring-cache
    Spring Cache abstraction for Spring Boot 3.x. Covers @Cacheable, @CacheEvict, @CachePut, cache managers (Caffeine, Redis, EhCache), TTL configuration, cache keys, conditional caching, and cache synchronization. USE WHEN: user mentions "spring cache", "@Cacheable", "@CacheEvict",…
  • 100redis-patterns
    Redis data structure patterns, caching strategies, distributed locks, rate limiting, pub/sub, and connection management for production applications. Use when adding caching, a distributed lock, rate limiting, or pub/sub with Redis, or when key design needs review.
  • 100redis
    Use when choosing a Redis data structure for a use case, implementing caching or rate limiting, building pub/sub or Streams-based real-time messaging, or writing atomic operations like distributed locks.
  • 100redis
    Redis in-memory data store. Covers data structures, caching, and pub/sub. Use for caching and real-time features. USE WHEN: user mentions "redis", "caching", "session storage", "rate limiting", "pub/sub", "sorted sets", "in-memory database", "cache invalidation" DO NOT USE FOR:…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.