尝试将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)