Redis統合

1686 ワード

依存を追加:

        org.springframework.boot
        spring-boot-starter-data-redis



        com.fasterxml.jackson.datatype
        jackson-datatype-jsr310


プロファイル:
#========Redis=========
# Redis     (   0,    16    )
spring.redis.database=0
# Redis     
spring.redis.host=192.168.17.135
# Redis       
spring.redis.port=6379
# Redis       (    )
spring.redis.password=admin
#         (          )
spring.redis.pool.max-active=50
#            (          )
spring.redis.pool.max-wait=5000
#            
spring.redis.pool.max-idle=8
#            
spring.redis.pool.min-idle=0
#       (  )
spring.redis.timeout=5000

シーケンス化の設定:
@Configuration
public class RedisConfig {

    //       
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate redisTemplate = new RedisTemplate<>();
        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
        GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
        redisTemplate.setConnectionFactory(connectionFactory);
        redisTemplate.setKeySerializer(stringRedisSerializer);
        redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer);
        redisTemplate.setHashKeySerializer(stringRedisSerializer);
        redisTemplate.setHashValueSerializer(genericJackson2JsonRedisSerializer);
        return  redisTemplate;
    }

}