Quickuse.Lock 快速应用.锁

环境:.net core 3.1

介绍

Quickuse.Lock 快速应用.锁,在多线程编程中,可能会有许多线程并发执行一段代码,以提高执行效率,在某些情况下我们锁是计算机协调多个进程或纯线程并发访问某一资源的机制, Quickuse.Lock类库提供常用锁使用方式,目前支持常用的 本地锁分布式锁

  • 本地锁 LocalLock

    使用Monitor实现,并且使用Monitor.TryEnter 通过设置防治死锁,

  • 分布式锁 GlobalLock

    使用Redis实现分布式锁

安装教程

  • 安装方式1

打开程序包管理器控制台输入 Install-Package Quickuse.Lock

  • 安装方式2

打开管理Nuget程序包 搜索Quickuse.Lock 安装

  • 安装方式3

打开地址 https://www.nuget.org/packages/Quickuse.Lock/

复制 PackageReference 配置到项目配置文件中自动加载

<PackageReference Include="Quickuse.Lock" Version="*.*.*" />

在Startup添加服务

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    services.AddQuickuseLock();//默认127.0.0.1:6379
    services.AddQuickuseLock("192.168.1.66:6379");//可以配置redis连接字符串

    services.AddControllersWithViews();
}

具体使用方式请查阅在线文档
在线文档 http://caisimon.gitee.io/quickuse.lock

原文地址:https://www.cnblogs.com/simoncai/p/13513528.html