All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.microsphere.spring.test.redis.RedisTestConfiguration Maven / Gradle / Ivy

There is a newer version: 0.0.3
Show newest version
package io.microsphere.spring.test.redis;

import io.microsphere.spring.test.redis.embedded.EnableEmbeddedRedisServer;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
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.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.embedded.RedisServer;

/**
 * Redis test configuration class configures the component list:
 * 
    *
  • {@link RedisTemplate RedisTemplate<Object,Object>}
  • *
  • {@link StringRedisTemplate}
  • *
  • {@link RedisServer}
  • *
* * @author Mercy * @since 1.0.0 */ @EnableEmbeddedRedisServer class RedisTestConfiguration { @Bean public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { RedisTemplate redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); redisTemplate.setKeySerializer(stringRedisSerializer); redisTemplate.setHashKeySerializer(stringRedisSerializer); redisTemplate.afterPropertiesSet(); return redisTemplate; } @Bean public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) { StringRedisTemplate redisTemplate = new StringRedisTemplate(); redisTemplate.setConnectionFactory(redisConnectionFactory); StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); redisTemplate.setKeySerializer(stringRedisSerializer); redisTemplate.setHashKeySerializer(stringRedisSerializer); redisTemplate.afterPropertiesSet(); return redisTemplate; } @Bean(destroyMethod = "destroy") public LettuceConnectionFactory redisConnectionFactory() { return new LettuceConnectionFactory(new RedisStandaloneConfiguration("127.0.0.1", 6379)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy