优化
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user