Sometimes I just want to play with some technology but not spend time installing and configuring components on my system and this is why I love Docker.

Use Docker to run Redis

Getting Docker is fairly trivial, simply go to the Docker Site, download and install the appropriate version for your operating system.

Docker Hub is the place to go for docker images and makes it super simple to download a container to play around with, example Redis:

    docker pull redis

Configuring and running the container is also relatively straightforward although exposing the port correctly so you can use it requires a small bit of config:

    docker run -d --name redisDev -p 6379:6379 redis

Check that the container is running correctly:

    docker ps

.Net Core Application

Now for some quick application scaffolding to test our Redis docker container. This bit assumes you have .Net Core running on your system.

Create a simple console application:

    dotnet new console 

Install a package to Redis client kindly open sourced by the good folk at Stack Overflow.

    dotnet add package StackExchange.Redis

Connecting, writing and reading to the Redis container is a snip, edit the Program.cs generated above:

    using System;
    using StackExchange.Redis;
 
    namespace RedisTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");

                IDatabase db = redis.GetDatabase();

                db.StringSet("thekey", "The Value");

                var returnValue = db.StringGet("thekey");

                Console.WriteLine(returnValue); 
            }
        }
    }

And from the commandline:

    dotnet run

Setting up a development environment with a database is so easy now Docker has matured, what’s not to like?