0

Currently, I am using ServiceStack.Redis to connect to Redis Cache server. The redis cache URL structure is like: redis://f:UIOPabcdXYZ@ip-172-31-81-144.manager.{domain}.io:33004

Below is a sample code to connect to Redis Cache using ServiceStack.Redis

var redisClientManagerPool = new RedisManagerPool(ConfigManager.RedisCacheUrl);

using (var client = redisClientManagerPool.GetClient())
{
    //SetClientData(key, client, data);
}

But the free version has certain restrictions and once it reaches the limit, it gives error like

The free-quota limit on '6000 Redis requests per hour' has been reached. Please see https://servicestack.net to upgrade to a commercial license or visit https://github.com/ServiceStackV3/ServiceStackV3 to revert back to the free ServiceStack v3

I want to use StackExchange.Redis to connect to redis cache. But I didn't get any code reference how to use the redis URL from https://stackexchange.github.io/StackExchange.Redis/Basics .

I am looking for any code reference to use redis cache URL like redis://f:UIOPabcdXYZ@ip-172-31-81-144.manager.domain.io:33004 to connect to redis cache server by using StackExchange.Redis nuget. Any help is appreciated.

Note: The current used library is .NET Standard 2.0 version of ServiceStack.Redis. The nuget name is ServiceStack.Redis.Core version 5.7.0.

Dukhabandhu Sahoo
  • 1,394
  • 1
  • 22
  • 44
  • Does this answer your question? [StackExchange.Redis simple C# Example](https://stackoverflow.com/questions/32888513/stackexchange-redis-simple-c-sharp-example) – Manish Jan 01 '20 at 11:12
  • No, I already tried that but it didn't work with the redis URL format. I didn't find any configuration related to redis:// URL structure in https://stackexchange.github.io/StackExchange.Redis/Configuration – Dukhabandhu Sahoo Jan 01 '20 at 11:16
  • have you tried servicestack-redis v 3.0.71. https://ppolyzos.com/2015/10/08/issues-when-downgrading-to-servicestack-redis-v3/ – Manish Jan 01 '20 at 11:39
  • The exact library is .NET Standard 2.0 version of ServiceStack.Redis. The nuget name is `ServiceStack.Redis.Core` version 5.7.0. Is there any equivalent free version? – Dukhabandhu Sahoo Jan 01 '20 at 12:19

1 Answers1

0

The StackExchange.Redis worked for redis://f:UIOPabcdXYZ@ip-172-31-81-144.manager.{domain}.io:33004 URL format. Below is the code reference:

var url = "redis://f:UIOPabcdXYZ@ip-172-31-81-144.manager.{domain}.io:33004";
var urlParts = url.Split("@ip-");
var password = urlParts[0].Split("redis://f:")[1].Trim();
var host = "ip-" + urlParts[1].Split(":")[0].Trim();
var port = int.Parse(urlParts[1].Split(":")[1].Trim());
var redisConfigurationOptions = new ConfigurationOptions
{
    AllowAdmin = false,
    Ssl = false,
    Password = password,
    EndPoints = {
                    {  host, port }
                }
};

var conn = ConnectionMultiplexer.Connect(redisConfigurationOptions);
var client = conn.GetDatabase();
client.StringSet(cacheKey, Newtonsoft.Json.JsonConvert.SerializeObject(data), TimeSpan.FromMinutes(30));

//To retrieve data
if (client.KeyExists(cacheKey))
{    
   var outputString = client.StringGet(cacheKey).ToString();    
}
else
{
  //cacheKey doesn't exists
}
Dukhabandhu Sahoo
  • 1,394
  • 1
  • 22
  • 44