Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Set Windows Azure Redis connection string on the portal #1152


User avatar
0
sampath created

Hi, This is not related to the ABP. But hope your experience will give some advice for me.

On redis helper method where I have maintained 2 Redis connection strings.This is on the Application layer.One is for the local and the other one is for the Azure redis server.Each and every time when I need to publish, I have to change it manually.Do you know any place to set published Redis connection string on the Azure portal or when I do the publish ? We can do that for the db connection string.But what about Redis connection string ? Thanks.

public class RedisConnectorHelper
    {
     private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
            new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("localhost,ConnectTimeout=10000"));//local host

     //private static readonly Lazy<ConnectionMultiplexer> LazyConnection =
     //   new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("Myredis.redis.cache.windows.net:6380,password=mypassword,ssl=True,abortConnect=False"));//production
}

3 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    You can define two conn string (say "Regis_Debug" and "Redis_Prod") in config file. Then you write an #if to get the correct connstr based on current configuration. Like:

    #if DEBUG
      return debug conn str
    #else
      return prod conn str
    #endif
    
  • User Avatar
    0
    sampath created

    Hi,

    You're the man.Thanks a lot.You have removed huge pain of me :)

    #if DEBUG
               private static readonly Lazy<ConnectionMultiplexer> LazyConnection =  new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("localhost,ConnectTimeout=10000"));//local host
         #else
                private static readonly Lazy<ConnectionMultiplexer> LazyConnection =  new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect("MyRedis.redis.cache.windows.net:6380,password=mypassord,ssl=True,abortConnect=False"));//production
         #endif
    
            public static ConnectionMultiplexer Connection => LazyConnection.Value;
    
  • User Avatar
    0
    hikalkan created
    Support Team

    You're welcome :)