1

Currently, I am using ServiceStack.Redis to connect to Redis Cache server. The redis cache URL structure is like: redis://f:[email protected].{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:[email protected]: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.

4
  • Does this answer your question? StackExchange.Redis simple C# Example Commented Jan 1, 2020 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 stackexchange.github.io/StackExchange.Redis/Configuration Commented Jan 1, 2020 at 11:16
  • have you tried servicestack-redis v 3.0.71. ppolyzos.com/2015/10/08/… Commented Jan 1, 2020 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? Commented Jan 1, 2020 at 12:19

1 Answer 1

0

The StackExchange.Redis worked for redis://f:[email protected].{domain}.io:33004 URL format. Below is the code reference:

var url = "redis://f:[email protected].{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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.