Commit b093ddf5 authored by Fumao Li's avatar Fumao Li

update

parent 93f1a89e
[*.cs]
# CS1591: 缺少对公共可见类型或成员的 XML 注释
dotnet_diagnostic.CS1591.severity = silent
......@@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31829.152
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixOne.RedisLab.Server", "MatrixOne.RedisLab\Server\MatrixOne.RedisLab.Server.csproj", "{E74DC0BB-70C0-4180-8747-6169787D4BCA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatrixOne.RedisLab.Server", "MatrixOne.RedisLab\Server\MatrixOne.RedisLab.Server.csproj", "{E74DC0BB-70C0-4180-8747-6169787D4BCA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixOne.RedisLab.Client", "MatrixOne.RedisLab\Client\MatrixOne.RedisLab.Client.csproj", "{389886B7-5EDF-4F6F-AB6D-F18586F56D66}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatrixOne.RedisLab.Client", "MatrixOne.RedisLab\Client\MatrixOne.RedisLab.Client.csproj", "{389886B7-5EDF-4F6F-AB6D-F18586F56D66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixOne.RedisLab.Shared", "MatrixOne.RedisLab\Shared\MatrixOne.RedisLab.Shared.csproj", "{0EE6723E-4EDC-4601-B544-7DB57CF5DE61}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MatrixOne.RedisLab.Shared", "MatrixOne.RedisLab\Shared\MatrixOne.RedisLab.Shared.csproj", "{0EE6723E-4EDC-4601-B544-7DB57CF5DE61}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{33A9AF30-A10D-4770-9CCF-92812F6E6B03}"
ProjectSection(SolutionItems) = preProject
......
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}
......@@ -40,7 +40,7 @@ else
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast");
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("api/WeatherForecast");
}
}
@page "/logs"
@using MatrixOne.RedisLab.Shared
@inject HttpClient Http
<h1>Logs</h1>
@if (logpack == null)
{
<p><em>Loading...</em></p>
}
else
{
<h3>File:@logpack.file</h3>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>time</th>
<th>level</th>
<th>message</th>
</tr>
</thead>
<tbody>
@foreach (var log in logpack.Logs)
{
<tr>
<td>@log.id</td>
<td>@log.time.ToLongTimeString()</td>
<td>@log.level</td>
<td>@log.message</td>
</tr>
}
</tbody>
</table>
}
@code {
private LogPack logpack;
protected override async Task OnInitializedAsync()
{
logpack = await Http.GetFromJsonAsync<LogPack>("api/Log/GetLastLog");
}
}
@page "/redis"
@using MatrixOne.RedisLab.Shared
@inject HttpClient Http
<h1>Redis</h1>
@if (keys == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>key</th>
<th>type</th>
</tr>
</thead>
<tbody>
@foreach (var key in keys)
{
<tr>
<td>@key.Name</td>
<td>@key.Type</td>
</tr>
}
</tbody>
</table>
}
@code {
private RedisKey[] keys;
protected override async Task OnInitializedAsync()
{
keys = await Http.GetFromJsonAsync<RedisKey[]>("api/Redis/LoadKeys");
}
}
......@@ -6,7 +6,7 @@
<div class="main">
<div class="top-row px-4">
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
<a href="/swagger/" target="_blank" class="ml-md-auto">Swagger</a>
</div>
<div class="content px-4">
......
......@@ -13,13 +13,13 @@
</NavLink>
</li>
<li class="nav-item px-3">
<a href="/swagger/" target="_blank" class="nav-link">
<span class="oi oi-arrow-right" aria-hidden="true"></span> Swagger
</a>
<NavLink class="nav-link" href="logs">
<span class="oi oi-bug" aria-hidden="true"></span> Logs
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="counter">
<span class="oi oi-plus" aria-hidden="true"></span> Counter
<NavLink class="nav-link" href="redis">
<span class="oi oi-plus" aria-hidden="true"></span> Redis
</NavLink>
</li>
<li class="nav-item px-3">
......
using CSRedis;
using MatrixOne.RedisLab.Shared;
using MatrixOne.RedisLab.Shared.services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace MatrixOne.RedisLab.Server.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class RedisController : ControllerBase
{
private readonly ILogger<RedisController> logger;
private readonly RedisService redis;
public RedisController(ILogger<RedisController> logger, RedisService redis)
{
this.logger = logger;
this.redis = redis;
}
[HttpGet("LoadKeys")]
public async Task<RedisKey[]> LoadKeys(string pattern = "*")
{
List<RedisKey> ret = new List<RedisKey>();
string[] keys = await redis.GetKeys(pattern);
foreach (var key in keys)
{
RedisKey info = new RedisKey
{
Name = key,
Type = await redis.GetKeyType(key)
};
ret.Add(info);
}
return ret.ToArray();
}
[HttpDelete("DelKeys")]
public async Task<long> DelKeys(string key)
{
return await redis.DelKeys(key);
}
[HttpGet("GetKeyType")]
public async Task<KeyType> GetKeyType(string key)
{
KeyType ret = await redis.GetKeyType(key);
return ret;
}
[HttpGet("GetKeyValue")]
public async Task<object> GetKeyValue(string key, long cursor = 0, long start = 0, long len = 0)
{
object ret = null;
ret = await redis.GetKeyValue(key, cursor, start, len);
return ret;
}
[HttpPost("SetKeyValue")]
public async Task<bool> SetKeyValue(string key, object value)
{
return await redis.SetKeyValue(key, value);
}
}
}
......@@ -13,6 +13,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.6.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="3.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
......
using MatrixOne.RedisLab.Shared.services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.ResponseCompression;
......@@ -49,6 +51,7 @@ namespace MatrixOne.RedisLab.Server
services.AddRazorPages();
services.AddSingleton<RedisService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
{ "id": "1", "time": "2021-11-15 16:22:46.0517", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 16:50:49.3349", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 16:52:30.0571", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 16:58:08.0180", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:02:41.3973", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:03:56.8854", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "2", "time": "2021-11-15 17:04:13.0705", "level": "INFO", "message": "swagger\u8def\u5f84:http:\/\/localhost:5000\/swagger" }
{ "id": "1", "time": "2021-11-15 17:04:26.7151", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "2", "time": "2021-11-15 17:04:36.0590", "level": "INFO", "message": "swagger\u8def\u5f84:http:\/\/localhost:5000\/swagger" }
{ "id": "1", "time": "2021-11-15 17:19:21.0740", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:12:17.9362", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:13:20.7245", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:14:42.8431", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:16:12.3898", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:17:08.5785", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:18:17.4340", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:07:46.6727", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "2", "time": "2021-11-15 17:08:03.5041", "level": "INFO", "message": "swagger\u8def\u5f84:http:\/\/localhost:5000\/swagger" }
{ "id": "1", "time": "2021-11-15 17:09:04.2050", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
{ "id": "1", "time": "2021-11-15 17:09:53.3218", "level": "INFO", "message": "\u65e5\u5fd7\u5f00\u59cb" }
......@@ -5,6 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSRedisCore" Version="3.6.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="NLog" Version="4.7.12" />
</ItemGroup>
......
using CSRedis;
namespace MatrixOne.RedisLab.Shared
{
public class RedisKey
{
public string Name { get; set; }
public KeyType Type { get; set; }
}
}
using CSRedis;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
namespace MatrixOne.RedisLab.Shared.services
{
/// <summary>
/// Redis连接信息对象实体
/// </summary>
public class ConnectionInfo
{
/// <summary>
/// Redis名称,用来标识不同的Redis地址,不能重复
/// </summary>
public string Key { get; set; }
/// <summary>
/// 连接信息,参见json配置信息
/// </summary>
public string Connection { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
}
public class RedisService
{
private readonly CSRedisClient _client;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="options"></param>
public RedisService(ILogger<RedisService> logger)
{
logger.LogInformation("============开始初始化Redis连接==================");
string con = "172.18.0.230:6379";
string psw = "MDNcVb924a";
Stopwatch watch = new Stopwatch();
watch.Start();
_client = new CSRedisClient( $"{con},password={psw}");
watch.Stop();
logger.LogInformation($"Redis 连接耗时(毫秒) = {watch.ElapsedMilliseconds}");
watch.Reset();
logger.LogInformation("============Redis连接完成==================");
}
public async Task<string[]> GetKeys(string pattern = "*")
{
string[] ret = await _client.KeysAsync(pattern);
return ret;
}
public async Task<long> DelKeys(string key)
{
return await _client.DelAsync(key);
}
public async Task<KeyType> GetKeyType(string key)
{
KeyType ret = await _client.TypeAsync(key);
return ret;
}
public async Task<object> GetKeyValue(string key, long cursor = 0, long start = 0, long len = 0)
{
object ret = null;
switch (await _client.TypeAsync(key))
{
default:
case KeyType.None:
case KeyType.String:
ret = await _client.GetAsync(key);
break;
case KeyType.List:
ret = await _client.LRangeAsync(key, start, start + len);
break;
case KeyType.Set:
ret = await _client.SScanAsync(key, cursor, "*", len);
break;
case KeyType.ZSet:
ret = await _client.ZScanAsync(key, cursor, "*", len);
break;
case KeyType.Hash:
ret = await _client.HScanAsync(key, cursor, "*", len);
break;
case KeyType.Stream:
ret = _client.XRange(key, start.ToString(), "+", len);
break;
}
return ret;
}
public async Task<bool> SetKeyValue(string key, object value)
{
return await _client.SetAsync(key, value);
}
}
}
\ No newline at end of file
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