NetPro.CsRedis 6.0.16

dotnet add package NetPro.CsRedis --version 6.0.16
                    
NuGet\Install-Package NetPro.CsRedis -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.CsRedis" Version="6.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetPro.CsRedis" Version="6.0.16" />
                    
Directory.Packages.props
<PackageReference Include="NetPro.CsRedis" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetPro.CsRedis --version 6.0.16
                    
#r "nuget: NetPro.CsRedis, 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.
#addin nuget:?package=NetPro.CsRedis&version=6.0.16
                    
Install NetPro.CsRedis as a Cake Addin
#tool nuget:?package=NetPro.CsRedis&version=6.0.16
                    
Install NetPro.CsRedis as a Cake Tool

RedisManager使用

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

appsetting.json


"RedisCacheOption": {
		"Enabled": true,
		"ConnectionString": [//如配置远程获取此节点可删除
			{
				"Key": "1", //连接串key别名,唯一,用来物理隔离
				"Value": "127.0.0.1:6379,password=123,defaultDatabase=0,poolsize=10,preheat=20,ssl=false,writeBuffer=10240,prefix=key前辍,testcluster=false,idleTimeout=10" //别名key对应的连接串
			}
		]
}

使用

启用redis服务
  • 默认注入方式,读取本地配置
  public void ConfigureServices(IServiceCollection services)
  {
    //新增redis缓存注入
    services.AddCsRedis().Build<SystemTextJsonSerializer>(configuration);//连接串默认读取配置文件的RedisCacheOption节点

  }
  • 自定义连接
public void ConfigureServices(IServiceCollection services, IConfiguration configuration = null, ITypeFinder typeFinder = null)
{
    //基于NetPro.Web.Api的程序,CsRedis支持自动根据配置文件初始化,如需覆盖默认初始化逻辑可在此重新初始化。
    services.AddCsRedis<SystemTextJsonSerializer>(configuration, GetConnectionString);
}

public List<ConnectionString> GetConnectionString(IServiceProvider serviceProvider)
{
    return new List<ConnectionString>
    {
        new ConnectionString
        {
            Key = "2",
            Value = "192.168.100.187:6379,password=,defaultDatabase=0,poolsize=10,preheat=20,ssl=false,writeBuffer=10240,prefix=key前辍,testcluster=false,idleTimeout=10"
        }
    };
}
构造函数注入
public class WeatherForecastController : ControllerBase
{
        private readonly IRedisManager _redisManager;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="redisManager"></param>
        public WeatherForecastController(
            IRedisManager redisManager)
        {
            _redisManager = redisManager;
        }
}

方法说明
   /// <summary>
   ///获取或者创建缓存 
   /// localExpiredTime参数大于0并且小于expiredTime数据将缓存到本地内存
   /// </summary>
   /// <typeparam name="T"></typeparam>
   /// <param name="key"></param>
   /// <param name="func"></param>
   /// <param name="expiredTime"></param>
   /// <param name="localExpiredTime">本地过期时间</param>
 T GetOrSet<T>(string key, Func<T> func = null, TimeSpan? expiredTime = null, int localExpiredTime = 0, string dbKey = default);
方法中调用

//同步方法
 var result = _redisManager.GetOrCreate<string>("1",func: ()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
 {
     return "1";
 },TimeSpan.FromeSecond(66));


//异步方法
  var resultAsync = await _redisManager.GetOrCreateAsync<string>("1",func: async()=>//获取key的值,没有找到则执行委托并将委托返回的值插入redis缓存
 {
     return await Task.FromResult("1") ;
 });
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (3)

Showing the top 3 NuGet packages that depend on NetPro.CsRedis:

Package Downloads
NetPro.ResponseCache

Package Description

NetPro.Analysic

Request analysis component, analysis of requests with custom policies, fusing, etc.

NetPro.Analysicn

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.0.16 368 7/24/2023
6.0.15 880 7/19/2022
6.0.14 914 7/10/2022
6.0.13 896 6/15/2022
6.0.12 911 6/15/2022
6.0.11 886 6/15/2022
6.0.10 913 6/11/2022
6.0.9 916 6/8/2022
6.0.8 947 5/26/2022
6.0.8-beta.3 170 5/24/2022
6.0.8-beta.2 145 5/24/2022
6.0.7 919 5/18/2022
6.0.6 920 4/28/2022
6.0.5 888 3/30/2022
6.0.5-beta.20 152 4/27/2022
6.0.5-beta.19 160 4/25/2022
6.0.5-beta.18 148 4/22/2022
6.0.5-beta.17 154 4/16/2022
6.0.5-beta.16 616 4/8/2022
6.0.5-beta.15 165 4/8/2022
6.0.5-beta.14 161 4/7/2022
6.0.5-beta.13 159 4/7/2022
6.0.5-beta.12 152 4/6/2022
6.0.5-beta.11 182 4/6/2022
6.0.5-beta.10 171 3/31/2022
6.0.5-beta.9 177 3/26/2022
6.0.5-beta.8 187 3/22/2022
6.0.5-beta.7 174 3/21/2022
6.0.5-beta.6 177 3/14/2022
6.0.5-beta.5 178 3/2/2022
6.0.5-beta.4 178 2/22/2022
6.0.5-beta.3 178 2/18/2022
6.0.5-beta.2 156 2/18/2022
6.0.5-beta.1 172 2/16/2022
6.0.4 768 2/10/2022
6.0.3 747 2/9/2022
6.0.3-beta.9 164 2/10/2022
6.0.3-beta.7 186 1/27/2022
6.0.3-beta.6 181 1/19/2022
6.0.3-beta.5 171 1/17/2022
6.0.3-beta.4 178 1/16/2022
6.0.3-beta.3 177 1/14/2022
6.0.3-beta.2 174 1/13/2022
6.0.3-beta.1 200 1/11/2022
6.0.2 491 1/6/2022
6.0.1 1,216 12/3/2021
3.1.11 676 11/17/2021
3.1.10 2,016 7/29/2021
3.1.9 2,442 7/1/2021
3.1.8 465 12/15/2020