Redis Windows

Redis for Windows – Super easy with Redis Labs

Redise – Redis Enterprise from Redis Labs, exponentially increases the power of Redis adding effortless scaling, stable high performance and unmatched resilience with multiple deployment choices and support for very large dataset sizes.

Redise Pack lets you install an enterprise grade Redis cluster in your environment of choice, whether an on-premises data-center or your preferred cloud platform. It gives you full control of your data and configuration – no clustering or sharding knowledge required! Download Redise Pack  and use with Windows clients or use the Redise Pack Docker image with Windows based host servers. 

Redise Cloud is a fully-managed cloud service for hosting and running Redis dataset without dealing with nodes, clusters, failure recovery or performance stabilization. Our technology does all that in a fully automated manner. Redise Cloud is available on all popular clouds and platforms-as-a-service.

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:

///open a connection to Redis

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

The output of the above code should be:



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