New DataProvider for Redis

Redis is an in-memory key-value database, so a typical NoSQL database. Since its initial release in 2009, it has become quite popular and now is, according to db-engines.com by far the most popular key-value database out there. With the new RedisDataProvider you can now use your Redis database within List & Label or Report Server.

Getting Started

You need to add a reference to combit.ListLabel24.RedisDataProvider.dll and StackExchange.Redis (NuGet) in your project.

For a simple connection without any registered hash tables (for hash tables see below) you just need to create an instance of RedisDataProvider and specify the connection information in the constructor (options documentation: https://stackexchange.github.io/StackExchange.Redis/Configuration#configuration-options):

var provider = new RedisDataProvider.RedisDataProvider("<YourServerURL or IP>");
ListLabel ll = new ListLabel();
ll.DataSource = provider;
ll.Design();

Using a Hash Table

Because Redis is a key-value database, it does not have regular tables as you would expect from a schematized RDBMS. Every entry is a unique key, therefore in Redis, a table consists of many keys which belong to one table: e. g. “user:001”, “user:002”, …

Since List & Label can’t know how the database is structured and could only guess which key belongs to which table, you need to define the layout for every hash table you want to use.

This can be done easily by adding a new lambda to the RegisteredHashTables. If RegisteredHashTables contains any values, every database collection key will be delegated to the lambda. Then you can check with your own specified schema, if the delegated key belongs to any table. If it belongs to a table, you need to return the table name or String.Empty/null if the key does not match any table. 

Example

var provider = new RedisDataProvider.RedisDataProvider("<YourServerURL or IP>");
provider.RegisteredHashTables.Add((s) =>
{
if (s.StartsWith("user"))
return "user";
return null;
});

Usage in the Report Server

For using Redis with the Report Server you need to add the data source “Redis” (under the category NoSQL). You need to at least specify the connection string for the data source (options documentation: https://stackexchange.github.io/StackExchange.Redis/Configuration#configuration-options).

If you want to use hash tables you need to specify the way the hash tables should be registered. For registering a hash table you must specify the value which the selected compare-function will check against and that will also be used as the table’s name.

Example

This configuration connects to the Redis server at 192.168.10.204, registers the hash tables “user” and “items” (separated by “|”) and uses the value as input for the compare-function (Starts with) and as the resulting table name.

To make this example clearer, this configuration translated to code (simplified) would look like this:

var provider = new RedisDataProvider.RedisDataProvider("192.168.10.204"); // connection string
provider.RegisteredHashTables.Add((s) =>
{
if (s.StartsWith("user"))
return "user";
return null;
});
provider.RegisteredHashTables.Add((s) =>
{
if (s.StartsWith("items"))
return "items";
return null;
});

Currently Supported Data Structures

NameSupported
Bitmaps
Hash
HyperLogLogs 
List
Set
SortedSet
String

Additional Information

  • Supported since List & Label 24.001
  • Supported since Report Server 24.001
  • Minimum .NET Framework Version: 4.6.1

The RedisDataProvider is IDisposable. Make sure to Dispose() the provider after usage. The sources for the provider are also available on our GitHub repository if you need to build against a different version.

Related Posts

Leave a Comment