wuchimedes | 18addec | 2025-04-03 17:59:02 +0800 | [diff] [blame^] | 1 | package com.example.g8backend.config; |
| 2 | |
| 3 | import org.springframework.context.annotation.Bean; |
| 4 | import org.springframework.context.annotation.Configuration; |
| 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 6 | import org.springframework.data.redis.core.RedisTemplate; |
| 7 | import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; |
| 8 | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| 9 | |
| 10 | @Configuration |
| 11 | public class RedisConfig { |
| 12 | |
| 13 | @Bean |
| 14 | public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) { |
| 15 | RedisTemplate<String, Object> template = new RedisTemplate<>(); |
| 16 | template.setConnectionFactory(connectionFactory); |
| 17 | template.setKeySerializer(new StringRedisSerializer()); |
| 18 | template.setValueSerializer(new StringRedisSerializer()); |
| 19 | return template; |
| 20 | } |
| 21 | } |