feat:完善缓存相关
This commit is contained in:
@@ -3,38 +3,48 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CSRedis;
|
||||
using Furion.ClayObject.Extensions;
|
||||
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Yi.Framework.Module.Caching;
|
||||
using Yi.Furion.Core.Rbac.Dtos.MonitorCache;
|
||||
|
||||
namespace Yi.Furion.Application.Rbac.Services.Impl
|
||||
{
|
||||
public class MonitorCacheService : IMonitorCacheService,IDynamicApiController,ITransient
|
||||
public class MonitorCacheService : IMonitorCacheService, IDynamicApiController, ITransient
|
||||
{
|
||||
private IMemoryCache _memoryCache;
|
||||
public MonitorCacheService(IMemoryCache memoryCache)
|
||||
private static List<MonitorCacheNameGetListOutputDto> monitorCacheNames => new List<MonitorCacheNameGetListOutputDto>()
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
new MonitorCacheNameGetListOutputDto{ CacheName="Yi:Login",Remark="登录验证码"},
|
||||
new MonitorCacheNameGetListOutputDto{ CacheName="Yi:User",Remark="用户信息"}
|
||||
};
|
||||
private Dictionary<string, string> monitorCacheNamesDic => monitorCacheNames.ToDictionary(x => x.CacheName, x => x.Remark);
|
||||
private CSRedisClient _cacheClient;
|
||||
public MonitorCacheService(RedisCacheClient redisCacheClient)
|
||||
{
|
||||
_cacheClient = redisCacheClient.Client;
|
||||
}
|
||||
//cacheKey value为空,只要name和备注
|
||||
|
||||
public List<MonitorCacheNameGetListOutputDto> GetName()
|
||||
{
|
||||
return new List<MonitorCacheNameGetListOutputDto>() {
|
||||
new MonitorCacheNameGetListOutputDto{ CacheName="Yi:Login",Remark="登录验证码"},
|
||||
new MonitorCacheNameGetListOutputDto{ CacheName="Yi:User",Remark="用户信息"}
|
||||
};
|
||||
//固定的
|
||||
return monitorCacheNames;
|
||||
}
|
||||
[HttpGet("key/{cacaheName}")]
|
||||
public List<string> GetKey([FromRoute] string cacaheName)
|
||||
{
|
||||
return new List<string>() { "1233124","3124","1231251","12312412"};
|
||||
var output = _cacheClient.Keys($"{cacaheName}:*");
|
||||
return new List<string>() { "1233124", "3124", "1231251", "12312412" };
|
||||
}
|
||||
|
||||
//全部不为空
|
||||
[HttpGet("value/{cacaheName}/{cacaheKey}")]
|
||||
public MonitorCacheGetListOutputDto GetValue([FromRoute] string cacaheName, [FromRoute] string cacaheKey)
|
||||
{
|
||||
return new MonitorCacheGetListOutputDto() { CacheKey= "1233124",CacheName= "Yi:Login",CacheValue="ttt",Remark= "登录验证码" };
|
||||
var value = _cacheClient.Get($"{cacaheName}:{cacaheKey}");
|
||||
return new MonitorCacheGetListOutputDto() { CacheKey = cacaheKey, CacheName = cacaheName, CacheValue = "ttt", Remark = monitorCacheNamesDic[cacaheName] };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
|
||||
var loginUser = GetLoginLogInfo(_httpContext);
|
||||
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
|
||||
//判断用户是否存在,否则添加集合
|
||||
if (!user )
|
||||
if (!user)
|
||||
{
|
||||
OnlineUserModel users = new(Context.ConnectionId)
|
||||
{
|
||||
@@ -57,9 +57,10 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
|
||||
_logger.LogInformation($"{DateTime.Now}:{name},{Context.ConnectionId}连接服务端success,当前已连接{clientUsers.Count}个");
|
||||
|
||||
//Clients.All.SendAsync(HubsConstant.MoreNotice, SendNotice());
|
||||
//当有人加入,向全部客户端发送当前总数
|
||||
Clients.All.SendAsync("onlineNum", clientUsers.Count);
|
||||
}
|
||||
//当有人加入,向全部客户端发送当前总数
|
||||
Clients.All.SendAsync("onlineNum", clientUsers.Count);
|
||||
|
||||
//Clients.All.SendAsync(HubsConstant.OnlineUser, clientUsers);
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user