spring-data-redis
БесплатноБез исполняемых скриптовНе проверенSpring Data Redis for caching, session storage, and data persistence. Covers RedisTemplate, @Cacheable, repositories, pub/sub, and distributed locks. USE…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Spring Data Redis - Quick Reference
Full Reference: See 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_docswith technology:spring-data-redisfor comprehensive documentation.
Dependencies
<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
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
@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
@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
@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
@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
redisskill 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 muta |
Установить spring-data-redis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditВложенные файлы
FAQ
Что делает скилл 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
Как установить скилл spring-data-redis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл spring-data-redis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic