Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into craver/stylecop
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCraver committed Aug 3, 2024
2 parents 1238494 + 4852cca commit a9a3e2b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: dotnet build Build.csproj -c Release /p:CI=true
- name: Start Redis Services (docker-compose)
working-directory: ./tests/RedisConfigs
run: docker-compose -f docker-compose.yml up -d
run: docker compose -f docker-compose.yml up -d
- name: StackExchange.Redis.Tests
run: dotnet test tests/StackExchange.Redis.Tests/StackExchange.Redis.Tests.csproj -c Release --logger trx --logger GitHubActions --results-directory ./test-results/ /p:CI=true
- uses: dorny/test-reporter@v1
Expand Down
2 changes: 1 addition & 1 deletion src/StackExchange.Redis/Configuration/LoggingTunnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ internal DirectoryLoggingTunnel(string path, ConfigurationOptions? options = nul
: base(options, tail)
{
this.path = path;
if (!Directory.Exists(path)) throw new InvalidOperationException("Directly does not exist: " + path);
if (!Directory.Exists(path)) throw new InvalidOperationException("Directory does not exist: " + path);
}

protected override Stream Log(Stream stream, EndPoint endpoint, ConnectionType connectionType)
Expand Down
4 changes: 3 additions & 1 deletion toys/KestrelRedisServer/KestrelRedisServer.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
54 changes: 35 additions & 19 deletions toys/KestrelRedisServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
using Microsoft.AspNetCore;
using KestrelRedisServer;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Hosting;
using StackExchange.Redis.Server;

namespace KestrelRedisServer
var server = new MemoryCacheRedisServer();

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<RespServer>(server);
builder.WebHost.ConfigureKestrel(options =>
{
public static class Program
{
public static void Main(string[] args) => CreateWebHostBuilder(args).Build().Run();
// HTTP 5000 (test/debug API only)
options.ListenLocalhost(5000);

// this is the core of using Kestrel to create a TCP server
// TCP 6379
options.ListenLocalhost(6379, builder => builder.UseConnectionHandler<RedisConnectionHandler>());
});

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseKestrel(options =>
{
// Moved to SocketTransportOptions.UnsafePreferInlineScheduling = true;
// options.ApplicationSchedulingMode = SchedulingMode.Inline;
var app = builder.Build();

// redis-specific hack - there is a redis command to shutdown the server
_ = server.Shutdown.ContinueWith(
static (t, s) =>
{
try
{
// if the resp server is shutdown by a client: stop the kestrel server too
if (t.Result == RespServer.ShutdownReason.ClientInitiated)
{
((IServiceProvider)s!).GetService<IHostApplicationLifetime>()?.StopApplication();
}
}
catch { /* Don't go boom on shutdown */ }
},
app.Services);

// HTTP 5000
options.ListenLocalhost(5000);
// add debug route
app.Run(context => context.Response.WriteAsync(server.GetStats()));

// TCP 6379
options.ListenLocalhost(6379, builder => builder.UseConnectionHandler<RedisConnectionHandler>());
}).UseStartup<Startup>();
}
}
// run the server
await app.RunAsync();
48 changes: 0 additions & 48 deletions toys/KestrelRedisServer/Startup.cs

This file was deleted.

0 comments on commit a9a3e2b

Please sign in to comment.