content: package com.alifetvaci.credit.authservice.redis;
  
  import com.alifetvaci.credit.authservice.redis.model.Session;
  import com.fasterxml.jackson.annotation.JsonAutoDetect;
  import com.fasterxml.jackson.annotation.PropertyAccessor;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import lombok.RequiredArgsConstructor;
  import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.redis.connection.RedisPassword;
  import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
  import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
  import org.springframework.data.redis.core.RedisTemplate;
  import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
  import org.springframework.data.redis.serializer.StringRedisSerializer;
  
  @RequiredArgsConstructor
  @Configuration
  public class RedisConfiguration {
  
      private final RedisProperties redisProperties;
  
      @Bean
      public LettuceConnectionFactory redisLocalConnectionFactory() {
          var redisStandaloneConfiguration = new RedisStandaloneConfiguration();
          redisStandaloneConfiguration.setHostName(redisProperties.getHost());
          redisStandaloneConfiguration.setPort(redisProperties.getPort());
          redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
          return new LettuceConnectionFactory(redisStandaloneConfiguration);
      }
  
      @Bean
      public RedisTemplate<String, Session> redisTemplate() {
          final RedisTemplate<String, Session> redisTemplate = new RedisTemplate<>();
          var objectMapper = new ObjectMapper();
          objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
  
          redisTemplate.setKeySerializer(new StringRedisSerializer());
          redisTemplate.setHashKeySerializer(new StringRedisSerializer());
  
          redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(objectMapper, Session.class));
          redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(objectMapper, Session.class));
  
          redisTemplate.setConnectionFactory(redisLocalConnectionFactory());
          return redisTemplate;
      }
  
  }
  