$/home/emma/random

Redis Notes

Described as an 'in-memory data store' that can be used as a database, cache or message broker. It supports various types of persistent storage also - dumping data to a disk or writing transaction logs. On a Linux system, the data is written to /var/redis by default. The configuration files can be created in /etc/redis. An instance of Redis might also require an file in /etc/init.d.

Related components:


Redis CLI

Check if the Redis server is running:

redis-cli ping

Start the Redis command line interface:

redis-cli

Set a row, or key-value:

set mykey somevalue

Read a value for a key:

get mykey

Write dataset and changes to persistent storage:

redis-cli save
redis-cli shutdown

Security

Redis has no authentication or access control by default.


Core Data Types


Using Redis with .NET

Import assembly references:

using NRedisStack;
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;

Instantiate Redis client:

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("[server address]");
IDatabase db = redis.GetDatabase();

To instantiate a Redis client that requires authentication:

ConfigurationOptions options = new ConfigurationOptions
{
    EndPoints = { { "[redis server address]", 6379 } },
    User = "[user]",
    Password = "[password]",
    Ssl = true,
    SslProtocols = System.Security.Authentication.SslProtocols.Tls12                
};

options.CertificateSelection += delegate
{
    return new X509Certificate2("[PFX file location]", "[password]");
};

ConnectionMultiplexer muxer = ConnectionMultiplexer.Connect(options);   

IDatabase conn = muxer.GetDatabase();

The User and Password values should be read from appsettings/configuration file, rather than hard-coded.


Resources

Redis Site Redis @ GitHub Redis: Getting Started# Redis and .NET

#development