NetPro.FreeRedis
6.0.14
.NET 6.0
This package targets .NET 6.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetPro.FreeRedis --version 6.0.14
NuGet\Install-Package NetPro.FreeRedis -Version 6.0.14
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.14" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.FreeRedis --version 6.0.14
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.FreeRedis, 6.0.14"
#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.14 // Install NetPro.FreeRedis as a Cake Tool #tool nuget:?package=NetPro.FreeRedis&version=6.0.14
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.
-
.NETCoreApp 3.1
- FreeRedis (>= 0.5.2)
- IdleBus (>= 1.5.2)
- NetPro.Startup (>= 6.0.14)
- Newtonsoft.Json (>= 13.0.1)
-
net6.0
- FreeRedis (>= 0.5.2)
- IdleBus (>= 1.5.2)
- NetPro.Startup (>= 6.0.14)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.