This commit is contained in:
tongfei
2024-04-17 16:33:51 +08:00
parent 7700bc37fb
commit 2e87e970a4
4 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WMS.Web.Domain.IService.Public
{
public interface IRedisConcurrentProcessService
{
bool CanAccessMethod(string cacheKey);
void UpdateAccessStatus(string cacheKey, bool canAccess);
}
}

View File

@@ -0,0 +1,29 @@
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using WMS.Web.Domain.IService.Public;
namespace WMS.Web.Domain.Services.Public
{
public class RedisConcurrentProcessService: IRedisConcurrentProcessService
{
private readonly RedisClientService _redisClientService;
public RedisConcurrentProcessService(RedisClientService redisClientService)
{
this._redisClientService = redisClientService;
}
public bool CanAccessMethod(string cacheKey)
{
// 使用 Redis 来存储并发控制标记
return _redisClientService.SetStringKey(cacheKey, "true", TimeSpan.FromMinutes(1));
}
public void UpdateAccessStatus(string cacheKey, bool canAccess)
{
// 更新 Redis 缓存项的值
_redisClientService.SetStringKey(cacheKey, canAccess.ToString(), TimeSpan.FromMinutes(1));
}
}
}