herokuredisspring-cloudredislabs

Using Spring Cloud Connector for Heroku in order to connect to multiple RedisLabs databases


I have a requirement for multiple RedisLabs databases for my application as described in their home page:

multiple dedicated databases in a plan

We enable multiple DBs in a single plan, each running in a dedicated process and in a non-blocking manner.

I rely on Spring Cloud Connectors in order to connect to Heroku (or Foreman in local) and it seems the RedisServiceInfoCreator class allows for a single RedisLabs URL i.e. REDISCLOUD_URL

Here is how I have configured my first redis connection factory:

@Configuration
@Profile({Profiles.CLOUD, Profiles.DEFAULT})
public class RedisCloudConfiguration extends AbstractCloudConfig  {
    
    @Bean
    public RedisConnectionFactory redisConnectionFactory() {
        PoolConfig poolConfig = ...
        return connectionFactory().redisConnectionFactory("REDISCLOUD", new PooledServiceConnectorConfig(poolConfig));
    }
...

How I am supposed to configure a second connection factory if I intend to use several redis labs databases?


Solution

  • Redis Cloud will set for you an env var only for the first resource in each add-on that you create.

    If you create multiple resources in an add-on, you should either set an env var yourself, or use the new endpoint directly in your code.