-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into craver/stylecop
- Loading branch information
Showing
5 changed files
with
40 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file was deleted.
Oops, something went wrong.