From 5791a788530e47ea130db341537b254376a44a3f Mon Sep 17 00:00:00 2001 From: "DESKTOP-E7L6HLO\\Noyan" Date: Sat, 29 Jun 2024 19:23:59 +0300 Subject: [PATCH] Task 17 : Define CacheConfig and RedisConfig --- .../ratelimiter/config/CacheConfig.java | 11 +++++++ .../ratelimiter/config/RedisConfig.java | 29 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/com/springboot/ratelimiter/config/CacheConfig.java create mode 100644 src/main/java/com/springboot/ratelimiter/config/RedisConfig.java diff --git a/src/main/java/com/springboot/ratelimiter/config/CacheConfig.java b/src/main/java/com/springboot/ratelimiter/config/CacheConfig.java new file mode 100644 index 0000000..721e925 --- /dev/null +++ b/src/main/java/com/springboot/ratelimiter/config/CacheConfig.java @@ -0,0 +1,11 @@ +package com.springboot.ratelimiter.config; + +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableCaching +public class CacheConfig { + +} + diff --git a/src/main/java/com/springboot/ratelimiter/config/RedisConfig.java b/src/main/java/com/springboot/ratelimiter/config/RedisConfig.java new file mode 100644 index 0000000..24466e0 --- /dev/null +++ b/src/main/java/com/springboot/ratelimiter/config/RedisConfig.java @@ -0,0 +1,29 @@ +package com.springboot.ratelimiter.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisConfig { + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(); + } + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(redisConnectionFactory); + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + return template; + } + +} +