Spring接続伝送における暗号化redis


Spring接続暗号化伝送redis
問題:springはAmazon ElastiCache伝送の暗号化機能のRedisノードに接続できない
解決策:sslをtrueに設定
  • コード構成RedisTemplate
  • package com.xxx.config;
    
    import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
    import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
    import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
    import org.springframework.data.redis.core.StringRedisTemplate;
    import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
    import org.springframework.data.redis.serializer.GenericToStringSerializer;
    import org.springframework.data.redis.serializer.StringRedisSerializer;
    
    @Configuration
    public class RedisTemplateConfig {
        @Value("${spring.redis.host}")
        private String host;
        @Value("${spring.redis.database}")
        private int database;
        @Value("${spring.redis.port}")
        private int port;
        @Value("${spring.redis.password}")
        private String password;
    
        @Bean
        public StringRedisTemplate rirStoreRedisTemplate() {
            RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
            redisStandaloneConfiguration.setDatabase(database);
            redisStandaloneConfiguration.setPort(port);
            redisStandaloneConfiguration.setHostName(host);
            redisStandaloneConfiguration.setPassword(password);
            LettuceClientConfiguration lettuceClientConfiguration = LettuceClientConfiguration.builder().useSsl().build();
            LettuceConnectionFactory factory = new LettuceConnectionFactory(redisStandaloneConfiguration, lettuceClientConfiguration);
            factory.afterPropertiesSet(); //        
            StringRedisTemplate redisTemplate = new StringRedisTemplate(factory);
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashValueSerializer(new GenericToStringSerializer<>(Object.class));
            redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Object.class));
            redisTemplate.setDefaultSerializer(new FastJsonRedisSerializer(Object.class));
            return redisTemplate;
        }
    
    }
    
  • springboot自動構成RedisTemplate
  • spring.redis.host=xxx
    spring.redis.port=6379
    spring.redis.database=1
    spring.redis.password=xxx
    spring.redis.ssl=true

    redis-cli接続
      https://amazonaws-china.com/cn/premiumsupport/knowledge-center/elasticache-connect-redis-node/