NetPro.FreeRedis 6.0.16

dotnet add package NetPro.FreeRedis --version 6.0.16                
NuGet\Install-Package NetPro.FreeRedis -Version 6.0.16                
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="NetPro.FreeRedis" Version="6.0.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.FreeRedis --version 6.0.16                
#r "nuget: NetPro.FreeRedis, 6.0.16"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetPro.FreeRedis as a Cake Addin
#addin nuget:?package=NetPro.FreeRedis&version=6.0.16

// Install NetPro.FreeRedis as a Cake Tool
#tool nuget:?package=NetPro.FreeRedis&version=6.0.16                

NetPro.FreeRedis使用

支持FreeRedis,支持分布式锁,支持多个Redis server

appsetting.json

"RedisCacheOption": {
  "ConnectionString": [
    {
      "Key": "1", //连接串key别名,唯一
      "Value": "127.0.0.1:6379,password=123,defaultDatabase=0,ssl=false,prefix=key前辍" //别名key对应的连接串
    }
  ]
}

使用

NetPro项目启用Redis服务

引用此nuget包,并且配置了RedisCacheOption,即可自动实现各种注册配置,无需再关心初始化等操作

非NetPro项目启用Redis服务
  • 默认注入方式,读取本地配置
public void ConfigureServices(IServiceCollection services)
{
    services.AddFreeRedis(configuration);
}
  • 自定义连接
public void ConfigureServices(IServiceCollection services, IConfiguration configuration = null, ITypeFinder typeFinder = null)
{
    // 基于NetPro.Web.Api的程序,FreeRedis支持自动根据配置文件初始化,如需覆盖默认初始化逻辑可在此重新初始化。
    services.AddFreeRedis(configuration, GetConnectionString);
}

public List<ConnectionString> GetConnectionString(IServiceProvider serviceProvider)
{
    return new List<ConnectionString>
    {
        new ConnectionString
        {
            Key = "2",
            Value = "127.0.0.1:6379,password=123,defaultDatabase=0,ssl=false,prefix=key前辍"
        }
    };
}

构造函数注入

public class WeatherForecastController : ControllerBase
{
        private readonly RedisClient _redisClient;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="redisIdleBus"></param>
        public WeatherForecastController(IdleBus<RedisClient> redisIdleBus)
        {
            // FreeRedis原生对象,以最原生方式调用,支持操作多个redis库;_redisIdleBus.Get("别名")
            _redisClient = redisIdleBus.Get("2");
        }
}

方法中调用


// Get
_redisClient.Get<string>(key);

// Publish
_redisClient.Publish(channel, message);

// 分布式锁
using var distributeLock = _redisClient.Lock(lockKey, timeoutSeconds, autoDelay);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
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
6.0.16 229 7/24/2023
6.0.15 481 7/19/2022
6.0.14 472 7/10/2022
6.0.13 463 6/15/2022
6.0.12 447 6/15/2022
6.0.11 443 6/15/2022
6.0.10 472 6/11/2022
6.0.9 440 6/8/2022
6.0.8 458 5/26/2022
6.0.8-beta.3 119 5/24/2022
6.0.8-beta.2 118 5/24/2022
6.0.7 469 5/18/2022