我有一個彈簧啟動應用程式。我想使用 jedisconnectionfactory 連接到 Redis 云服務器,但我做不到。實際上,當我使用本地 Redis 服務器時它可以作業。
我寫的 Redis 配置如下。
@Configuration
public class RedisConfig {
@Bean
public JedisConnectionFactory connectionFactory() {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName( "redis-cli -u redis://redis-19735.c1.us-east1-2.gce.cloud.redislabs.com");
configuration.setPort(19735);
configuration.setUsername("<username_goes_here>");
configuration.setPassword("<password_goes_here>");
return new JedisConnectionFactory(configuration);
}
@Bean
public RedisTemplate<String, Object> redisTemplate(){
RedisTemplate<String,Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}
你也可以在下面看到我的 Redis 云資料庫。

你能幫我看看如何連接它。我嘗試使用 jedisconnectionfactory 連接 Redis 云資料庫,但我做不到。
uj5u.com熱心網友回復:
簡單地輸入主機名redis-19735.c1.us-east1-2.gce.cloud.redislabs.com。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/531600.html
