Redis Enterprise For Windows

High Availability and scalability using Redis Labs technology

Redis Enterprise On The Windows Platform

Redis Enterprise offers many options to develop applications for Redis on Windows platform. This page will get you started with connecting your .NET based application to any Redis Enterprise database. You will also learn about all the deployment options you have while running your application on Windows.

.NET Redis Client

If you are developing apps for Redis on the Windows platform using C#, then you will need a .NET Redis client. Here’s the complete list of .NET clients from redis.io. StackExchange.Redis is a popular choice among .NET developers.

Deployment Options

The variety of deployment options available in Redis Enterprise enables you to deploy your Redis database closer to your application so that you achieve local data access latency.

Docker On Windows

Redis Enterprise can be deployed as a Docker container on Windows. This is a popular deployment option for your development environment. Each container represents a node in a Redis Enterprise Cluster. You could deploy multi-node cluster on a single host machine. Learn more about getting started as a Docker container.

Redis Enterprise as a hosted service on Azure

Redis Enterprise as a hosted service delivers stable high performance, effortless scaling and robust high availability features including persistence, cross zone/region/datacenter replication and instant automatic failover, with no data loss. In this deployment option, you can get started with Redis Enterprise in less than 2 minutes. You can signup for free and enjoy Redis Lab’s 30 MB free plan for unlimited time. Once you sign up you can create a new Redis database on Azure platform.

Fully Managed Redis Enterprise in your Azure Virtual Network (VNet)

Redis Enterprise as a fully managed service delivers cost effective, stable high performance Redis databases in dedicated clusters within your Azure VNet, with the option to run on RAM or on Flash as an extension.

As software on your server instance on Azure

Redis Enterprise downloadable software allows you to deploy and run the Redis database in your environment of choice – on-premises data center or your preferred public or private cloud platform with full control of your data and configuration. Enjoy the 30 day free trial of Redis Enterprise software.

On other cloud platforms

If you are developing and deploying your applications on the other cloud platforms, Redis Enterprise as a hosted service is available on Amazon Web Services (AWS), Google Cloud Platform (GCP), and IBM SoftLayer. Redis Enterprise as a fully managed service is available in Virtual Private Cloud(VPC) environment of AWS and GCP.

Using Redis with .Net C#

In order to use Redis with C# you will need a C# Redis client. In following sections, we will demonstrate the use of StackExchange.Redis, General purpose Redis client. Additional C# clients for Redis can be found under the C# section of the Redis Clients page.

Installing StackExchange.Redis

StackExchange.Redis’ installation instructions are given in the “Installation” section of its README file. It can be installed via the nuget package manager console with the following command:

PM> Install-Package StackExchange.Redis

Opening a Connection to Redis Using StackExchange.Redis

The following code creates a connection to Redis using StackExchange.Redis:

using StackExchange.Redis;

readonly ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect("hostname:port,password=password");
IDatabase conn = muxer.GetDatabase();

To adapt this example to your code, make sure that you replace the following values with those of your database:

  • In line 1, the first part of the string argument to Connect should be your database’s endpoint
  • In line 1, the second part of the string argument to Connect should be your database’s password

Connection Pooling with StackExchange.Redis

While StackExchange.Redis does not provide direct means for conventional connection pooling, we recommend you share and reuse the ConnectionMultiplexer object. The ConnectionMultiplexer object should not be created per operation – it is to be created only once at the beginning and reused for the duration of the run. ConnectionMultiplexer is thread-safe so it can be safely shared between threads. For more information, refer to StackExchange.Redis’ Basic Usage document.

Using SSL and StackExchange.Redis

StackExchange.Redis is the first Redis client that natively supported SSL. The following code opens an SSL connection:

using StackExchange.Redis;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

var options = new ConfigurationOptions
{
    EndPoints = { "hostname:port" },
    Password = "password",
    Ssl = true
};
options.CertificateSelection += delegate {
            return new X509Certificate2("d:\path\filname.pfx", "");
        };

readonly ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect(options);
IDatabase conn = muxer.GetDatabase();
  • In line 6, the first part of the string argument should be your database’s endpoint or IP address
  • In line 6, the second part of the string argument should be your database’s port
  • In line 7, the string argument should be your database’s password
  • In line 11, replace with the path to your .pfx file

Converting Certificates from .key to .pfx Format

To easily convert a .key certificate to .pfx format use OpenSSL:

$ openssl pkcs12 -export -in user.crt -inkey user_private.key -certfile garantia_ca.pem -out certificate.pfx 

Important: if you’re using a self-signed certificate, remember to install it on your server with the Certificate Manager tool.

Using SSL and a StackExchange.Redis-based Provider

Sometimes you need to use a 3rd-party library, such as when running a session on a cache provider that connects to Redis with the StackExchange.Redis client. When you need to provide an SSL certificate for the connection and the 3rd-party library does not expose a public interface for it, you can “sideload” the certificate to StackExchange.Redis by setting the following environment variables:

  • SERedis_ClientCertPfxPath should be set to the path of your .pfx file
  • SERedis_ClientCertPassword should be set to the password of your .pfx file

Reading and Writing Data with StackExchange.Redis

Once connected to Redis, you can start reading and writing data. The following code snippet writes the value bar to the Redis key foo, reads it back, and prints it:

///<summary>
///open a connection to Redis
///</summary>
...

conn.StringSet("foo", "bar");
var value = conn.StringGet("foo");
Console.WriteLine(value);

The output of the above code should be:

bar

 

For more information on using Redis Labs’ products and services with net-c please see the Howto page.