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; + } + +} +