This commit is contained in:
wangyu 2023-08-25 14:10:51 +08:00
commit 1049ec9a97
8 changed files with 160 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.vs
bin
obj
/.config
*.user

45
Program.cs Normal file
View File

@ -0,0 +1,45 @@
using Microsoft.Extensions.Caching.Distributed;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddStackExchangeRedisCache(options =>
{
options.Configuration = builder.Configuration["Redis"];
options.InstanceName = "CacheData_";
});
var app = builder.Build();
var CacheDictionary = new Dictionary<string, string>();
// Configure the HTTP request pipeline.
app.MapPost("/CacheData/Set", async (HttpRequest request, IDistributedCache cache, string key) =>
{
string body = "";
using (StreamReader stream = new StreamReader(request.Body))
{
body = await stream.ReadToEndAsync();
}
cache.SetString(key, body);
return "success";
});
app.MapGet("/CacheData/Get", (HttpContext httpContext, IDistributedCache cache, string key) =>
{
var cacheString = cache.GetString(key);
if (!string.IsNullOrWhiteSpace(cacheString))
{
httpContext.Response.ContentType = "application/json";
return cacheString;
}
else
{
httpContext.Response.StatusCode = 404;
return string.Empty;
}
});
app.Run();

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\net7.0\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<ProjectGuid>295af217-802a-4cc5-a87c-ce1d68ed553f</ProjectGuid>
<SelfContained>false</SelfContained>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59800",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5120",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

13
Sinet.CacheService.csproj Normal file
View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="7.0.10" />
</ItemGroup>
</Project>

25
Sinet.CacheService.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34004.107
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinet.CacheService", "Sinet.CacheService.csproj", "{295AF217-802A-4CC5-A87C-CE1D68ED553F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{295AF217-802A-4CC5-A87C-CE1D68ED553F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{295AF217-802A-4CC5-A87C-CE1D68ED553F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{295AF217-802A-4CC5-A87C-CE1D68ED553F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{295AF217-802A-4CC5-A87C-CE1D68ED553F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D0D0CC9-4D7E-46A8-A5C2-7B949335348B}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

11
appsettings.json Normal file
View File

@ -0,0 +1,11 @@
{
"Urls": "http://*:5120",
"Redis": "localhost:6379,user=redis,password=password",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}