Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
performance
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zry
performance
Commits
ba95946d
Commit
ba95946d
authored
Apr 10, 2020
by
ruyun.zhang@suvalue.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
弃用REDIS
parent
6e161b9d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
11 deletions
+19
-11
performance/Performance.Api/Startup.cs
+4
-2
performance/Performance.Services/Hubs/AllotLogHub.cs
+15
-9
No files found.
performance/Performance.Api/Startup.cs
View file @
ba95946d
...
...
@@ -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
=>
{
...
...
performance/Performance.Services/Hubs/AllotLogHub.cs
View file @
ba95946d
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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment