RedisNet 1.2.1

.NET 5.0
dotnet add package RedisNet --version 1.2.1
NuGet\Install-Package RedisNet -Version 1.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RedisNet" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RedisNet --version 1.2.1
#r "nuget: RedisNet, 1.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install RedisNet as a Cake Addin
#addin nuget:?package=RedisNet&version=1.2.1

// Install RedisNet as a Cake Tool
#tool nuget:?package=RedisNet&version=1.2.1

Local Test

New Features

  • Compression (increase your heavy redis calls performance by 50%)
public void ConfigureServices(IServiceCollection services)
{
    var redis2ConfigurationOptions = ConfigurationOptions.Parse("localhost:6379");
    redis2ConfigurationOptions.ReconnectRetryPolicy = new ExponentialRetry(1000);
    services.AddRedisDotNet(new RedisCacheOptions()
    {
        ConfigurationOptions = redis2ConfigurationOptions,
        CompressionOption = new CompressionOption()
        {
            TriggerByteSize = 100 * 1024
        }
    });
}

When the value size of a redis key exceeds 100 Kilo-Bytes it will apply gzip compression algorithm to decrease the size and automatically upon retrieval it will decompress it so the whole process is transparent from the client's perspective. The compression will decrease the size of the data packets through the network therefore the performances of the redis call will increase by 50%.

  • Key deletion with regex

Compression Benchmark Results


BenchmarkDotNet=v0.12.1, OS=macOS 11.3 (20E232) [Darwin 20.4.0]
Intel Core i7-9750H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.201
  [Host] : .NET Core 3.1.13 (CoreCLR 4.700.21.11102, CoreFX 4.700.21.11602), X64 RyuJIT DEBUG


Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
WithCompressionBenchmark 668.2 ms 13.34 ms 27.24 ms - - - 4.88 MB
WithoutCompressionBenchmark 1,387.1 ms 26.92 ms 37.74 ms - - - 2.39 MB

Usage Method 1

Single redis server

Prerequisite

docker run --name redis1 -d -p 6379:6379  redis redis-server --appendonly yes
public void ConfigureServices(IServiceCollection services)
{
    var redis2ConfigurationOptions = ConfigurationOptions.Parse("localhost:6379");
    redis2ConfigurationOptions.ReconnectRetryPolicy = new ExponentialRetry(1000);
    services.AddRedisDotNet(new RedisCacheOptions()
    {
        ConfigurationOptions = redis2ConfigurationOptions
    });
}

public class TestController : Controller
{
    private readonly IRedisService _redisService;
    public TestController(IRedisService redisService){
        _redisService = redisService;
    }

    public IActionResult Get(string key){
        var result = _redisService.GetString(key);
        return OK(result);
    }

    public async Task<IActionResult> GetAsync(string key){
        var result = await _redisService.GetStringAsync(key);
        return OK(result);
    }
}


Usage Method 2

Multiple Redis servers

Prerequisite

docker run --name redis1 -d -p 6379:6379  redis redis-server --appendonly yes
docker run --name redis2 -d -p 6380:6380  redis redis-server --appendonly yes
public void ConfigureServices(IServiceCollection services)
{
    var redis1ConfigurationOptions = ConfigurationOptions.Parse("localhost:6379");
    redis1ConfigurationOptions.ReconnectRetryPolicy = new ExponentialRetry(1000);
    services.AddRedisDotNet<Redis1>(new RedisCacheOptions()
    {
       ConfigurationOptions = redis1ConfigurationOptions
    });

    var redis2ConfigurationOptions = ConfigurationOptions.Parse("localhost:6380");
    redis2ConfigurationOptions.ReconnectRetryPolicy = new ExponentialRetry(1000);
    services.AddRedisDotNet<Redis2>(new RedisCacheOptions()
    {
       ConfigurationOptions = redis2ConfigurationOptions
    });
}


public class Redis1 : RedisService<Redis1>
{
    public Redis1(IOptionsMonitor<RedisCacheOptions> cacheOptions) : base(cacheOptions)
    {
    }
}


public class Redis2 : RedisService<Redis2>
{
    public Redis2(IOptionsMonitor<RedisCacheOptions> cacheOptions) : base(cacheOptions)
    {
    }
}

public class Redis1Controller : ControllerBase
{
    private readonly Redis1 _redis1;

    public Redis1Controller(Redis1 redis1)
    {
        _redis1 = redis1;
    }

    [HttpGet]
    public async Task<IActionResult> Get()
    {
        return Ok(await _redis1.GetStringAsync("redis1"));
    }
}


public class Redis2Controller : ControllerBase
{
    private readonly Redis2 _redis2;

    public Redis2Controller(Redis2 redis2)
    {
        _redis2 = redis2;
    }

    [HttpGet]
    public async Task<IActionResult> Get()
    {
        return Ok(await _redis2.GetStringAsync("redis2"));
    }
}


Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 265 5/12/2021
1.1.1 203 5/12/2021
1.1.0 214 5/10/2021
1.0.0 243 3/4/2021