Deep Dive Into ASP.NET Core with Redis - Day 11


In case you missed the other days:
Day 1 Deep Dive
Day 2 Deep Dive with MongoDB
Day 3 Deep Dive with MongoDB
Day 4 Deep Dive with MongoDB
Day 5 Deep Dive with MongoDB
Day 6 Deep Dive with Mongoose
Day 7 Deep Dive with Clustering
Day 8 Deep Dive with PM2
Day 9 Deep Dive with Restify
Day 10 Deep Dive with Redis

I was originally going to deep dive into AWS tonight, but the excitement over redis last night had me eager to switch gears a bit and get redis up and running in ASP.NET Core.


I will assume you have downloaded and installed the redis server. If you're on Windows, you can download the Windows port or if you're on Linux.

Setting it up in ASP.NET

Unsure of the "approved" client, I searched around on redis's official site for some clients to try out. Based on that list and nuget, I chose to at least start with StackExchange.Redis. To get going simply issue a nuget command:

Install-Package StackExchange.Redis
Or search in NuGet for StackExchange.Redis. As of this writing I am using the latest version, 1.1.605.

To get a redis database up and running in ASP.NET was extremely painless, just a few connection lines and then an async call to set the key/value:

private static ConnectionMultiplexer redis;
private IDatabase db;

public async Task Get(int id) {
    if (redis == null) {
        redis = ConnectionMultiplexer.Connect("localhost");

    if (db == null) {
        db = redis.GetDatabase();

    await db.StringSetAsync(id.ToString(), 2, flags: CommandFlags.FireAndForget);

    return "OK";


Interested to see the performance differences between how Node.js and ASP.NET Core performed with the same test. The numbers speak for themselves:

The performance results were interesting to say the least after having pretty near identical MongoDB results. Wondering if maybe there was a Kestrel difference, I re-ran the test:

Better, but not as dramatic as I would assume.

Next up...

Seeing as how the performance wasn't anywhere close to that of Node.js, I am wondering if utilzing the DI found in ASP.NET Core would alleviate the performance issues. My original intent was to spend Saturday adding Redis into my blogging platform for caching, but as of right now I will hold off until I can figure out the reason for the huge delta. All of the code thus far is committed on GitHub.
none on this post