Home

Awesome

Warden Redis Watcher

Warden

OPEN SOURCE & CROSS-PLATFORM TOOL FOR SIMPLIFIED MONITORING

getwarden.net

BranchBuild status
mastermaster branch build status
developdevelop branch build status

RedisWatcher can be used either for simple database monitoring (e.g. checking if a connection can be made) or more advanced one which may include running a specialized query.

Installation:

Available as a NuGet package.

dotnet add package Warden.Watchers.Redis

Configuration:

Please note that either WithConnectionProvider() or WithDatabaseProvider() methods can be used to achieve the same goal, which is getting the IRedis instance.

Example of configuring the watcher via provided configuration class:

var configuration = RedisWatcherConfiguration
    .Create(1, "localhost")
    .WithQuery("get test")
    .EnsureThat(results => results.Any(x => x == "test-value"))
    .Build();
var redisWatcher = RedisWatcher.Create("Redis watcher", configuration);

var wardenConfiguration = WardenConfiguration
    .Create()
    .AddWatcher(redisWatcher )
    //Configure other watchers, hooks etc.

Example of adding the watcher directly to the Warden via one of the extension methods:

var wardenConfiguration  = WardenConfiguration
    .Create()
    .AddRedisWatcher("localhost", 1, cfg =>
    {
        cfg.WithQuery("get test")
           .EnsureThat(results => results.Any(x => x == "test-value"));
    })
    //Configure other watchers, hooks etc.

Please note that you may either use the lambda expression for configuring the watcher or pass the configuration instance directly. You may also configure the hooks by using another lambda expression available in the extension methods.

Check result type:

RedisWatcher provides a custom RedisWatcherCheckResult type which contains additional values.

public class RedisWatcherCheckResult: WatcherCheckResult
{
    public int Database { get; }
    public string ConnectionString { get; }
    public string Query { get; }
    public IEnumerable<dynamic> QueryResult { get; }
}

Custom interfaces:

public interface IRedisConnection
{
    string ConnectionString { get; }
    TimeSpan Timeout { get; }
    Task<IRedis> GetDatabaseAsync(int database);
}

IRedisConnection is responsible for making a connection to the database. It can be configured via the WithConnectionProvider() method. By default it is based on the StackExchange.Redis.

public interface IRedis
{
    Task<IEnumerable<dynamic>> QueryAsync(string query);
}

IRedis is responsible for executing the query on a database. It can be configured via the WithRedisProvider() method. By default, it is based on the StackExchange.Redis.