Superwalnut.RedisClusterTemplate

This is a project template for Redis Cluster + Docker + .Net Core 3.1 API, using `dotnet new -i Superwalnut.RedisClusterTemplate` to install project as a template, And using `dotnet new redis-dotnet-core` to create a project with the template.


Keywords
dotnet-new, templates, redis, docker, dotnet-core, netcore3, redis-cluster, redis-dotnet
Install
Install-Package Superwalnut.RedisClusterTemplate -Version 1.0.200305629

Documentation

Project Template - Redis Cluster + .Net Core 3.1 API + Docker

This is a project template that saves your time create redis cluster in docker with a dotnet core app to consume from scratch. All you need to do is using docker-compose up and you already have 1 master + 3 slaves redis cluster.

Read full medium article https://medium.com/@mrkevin.wang/create-redis-cluster-docker-net-core-3-1-api-for-distributed-caching-ff0ba1673231

Pre-request

Table of Contents


Features

This is a development project template, it is NOT production ready. It only kickstarting your project so that you don't need to build from scratch.

  • Pre-built and configured redis cluster in docker
  • Pre-built a sample web API in .net core 3.1
  • The sample web API is built with DockerFile and runs in docker
  • Easy to scale redis with n-masters & n-slaves in docker
  • Built in generic cache client using ServiceStack.Redis

Installation

$ dotnet new -i Superwalnut.RedisClusterTemplate

You should see 'Redis .Net Core Template' in your template list by dotnet new -l

Redis .net core Template Screenshot

  • Using dotnet new redis-dotnet-core -n <your-project-name> to create a project with your own project name using this template
$ dotnet new redis-dotnet-core -n RedisDemo -o RedisDemo

This creates a project in folder RedisDemo

Redis Demo


Usage

  • Default - 1 master + 1 slave + 1 api

Go to the /docker, you will see docker-compose.yml file, this is where you can run

$ docker-compose up --build
  • Swarm Mode - 1 master + 3 slaves + 1 api

Run docker-compose with compatibility mode, it will apply preset deploy to run docker swarm mode

    deploy:
      replicas: 3
$ docker-compose --compatibility up --build
  • Advanced - n-Master + n-Slaves + api

To run n number of masters and slaves, you will need to configure a couple of things in docker-compose.yml

Configure connection strings in api container, add n-number of master and n-number of slaves connection strings

    - Redis__0=docker_redis-master_1:6379
    - Redis__1=docker_redis-replica_1:6379
    - Redis__2=docker_redis-replica_2:6379
    - Redis__3=docker_redis-replica_3:6379

Add or configure deploy section to the number you wanted

    deploy:
    replicas: 3

Documentation

  • TODO

Support

Reach out to me at one of the following places!


License

License


Reference

  • docker stop all

ocker stop $(docker ps -a -q) docker rm $(docker ps -a -q)

  • run command docker-compose up --detach --scale redis-master=1 --scale redis-replica=3

docker-compose --compatibility up --build -p redis

  • pack the project template dotnet pack

dotnet build -c Release

  • install template

dotnet new -i

  • create project

dotnet new redis-dotnet-core -n MyProject --force

  • stop docker docker ps -q | xargs -L1 docker stop

  • start docker open --background -a Docker

  • generate dev-cert ssl dotnet dev-certs https --clean

dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p password

dotnet dev-certs https --trust