尝试将SpringBoot与带有Elasticache的SpringData结合使用:
application.properties:
spring.redis.host=XXXX-dev.XXXX.clusXXXcfg.XXX.cache.amazonaws.com
spring.redis.port=6379
Run Code Online (Sandbox Code Playgroud)
CacheConfiguration:
@Configuration
@PropertySource("classpath:application.properties")
public class CacheConfiguration {
@Value("${spring.redis.host}")
private String redisHostName;
@Bean
public RedisTemplate<String, Company> redisTemplate() {
RedisTemplate<String, Company> template = new RedisTemplate();
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
@Bean
JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(redisHostName);
factory.setUsePool(true);
return factory;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
Run Code Online (Sandbox Code Playgroud)
}
服务电话:
@Autowired
RedisTemplate<String, Company> redisTemplate;
private ValueOperations valueOperations;
@PostConstruct
private void init() {
valueOperations = redisTemplate.opsForValue();
}
@Override
public String createOtp(Company company) {
String …Run Code Online (Sandbox Code Playgroud) 我使用 spring-data-redis 版本 1.7.0.M1,jedis 版本 2.8.0\n这是我的配置
\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">\n <property name="connectionFactory" ref="redisConnectionFactory"></property>\n <property name="keySerializer">\n <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>\n </property>\n <property name="hashKeySerializer">\n <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>\n </property>\n <property name="valueSerializer">\n <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>\n </property>\n <property name="hashValueSerializer">\n <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>\n </property>\n</bean>\nRun Code Online (Sandbox Code Playgroud)\n\n并使用 \xe3\x80\x90redisTemplate.opsForValue().get("foo")\xe3\x80\x91 进行测试
\n\n抛出异常
\n\n org.springframework.dao.InvalidDataAccessApiUsageException: MOVED 12182 192.168.1.223:7002; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 12182 192.168.1.223:7002\nRun Code Online (Sandbox Code Playgroud)\n\n使用spring-data-redis 1.7.0.M1时如何配置redis-cluster?
\n