弃用REDIS

parent 6e161b9d
......@@ -135,10 +135,12 @@ public void ConfigureServices(IServiceCollection services)
#endregion
#region redis
var csredis = new CSRedis.CSRedisClient(connection.Value.RedisConnectionString);
RedisHelper.Initialization(csredis);
//var csredis = new CSRedis.CSRedisClient(connection.Value.RedisConnectionString);
//RedisHelper.Initialization(csredis);
#endregion
services.AddMemoryCache();
#region hangfire
services.AddHangfire(config =>
{
......
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
......@@ -11,10 +12,14 @@ namespace Performance.Services
public class AllotLogHub : Hub
{
private readonly ILogger<AllotLogHub> logger;
private readonly IMemoryCache cache;
public AllotLogHub(ILogger<AllotLogHub> logger)
public AllotLogHub(
ILogger<AllotLogHub> logger,
IMemoryCache cache)
{
this.logger = logger;
this.cache = cache;
}
public override Task OnConnectedAsync()
......@@ -26,14 +31,14 @@ public override Task OnDisconnectedAsync(Exception exception)
{
var connectionId = Context.ConnectionId;
logger.LogDebug($"日志推送 断开连接{connectionId}");
string key = $"AllotLogGroup_{connectionId}";
//1 查询用户分组信息
var groupName = "";
//2 删除数据库中用户分组数据
if (RedisHelper.HExists("AllotLogGroup", connectionId))
if (cache.TryGetValue(key, out groupName))
{
groupName = RedisHelper.HGet("AllotLogGroup", connectionId);
RedisHelper.HDel("AllotLogGroup", connectionId);
cache.Remove(key);
}
logger.LogDebug($"日志推送 断开连接{connectionId}-{groupName}");
......@@ -45,16 +50,17 @@ public override Task OnDisconnectedAsync(Exception exception)
public async Task AddGroup(string token, string groupName)
{
var connectionId = Context.ConnectionId;
if (!RedisHelper.HExists("AllotLogGroup", connectionId))
string key = $"AllotLogGroup_{connectionId}";
if (cache.TryGetValue(key, out groupName))
{
//1 向数据库中插入用户及分组信息
RedisHelper.HSet("AllotLogGroup", connectionId, groupName);
cache.Remove(key);
}
cache.Set(key, groupName, new TimeSpan(1, 0, 0));
logger.LogDebug($"日志推送 添加用户组{connectionId}-{groupName}");
//2 将用户插入分组
await Groups.AddToGroupAsync(connectionId, groupName);
}
}
public async Task SendMessage(string groupName, string message)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment