Redis Filters

The Redis Filters provide connectivity with a Redis Server instance using the ServiceStack.Redis library. To enable, install the ServiceStack.Redis NuGet Package, then register a Redis Client Manager in the IOC:

container.AddSingleton<IRedisClientsManager>(() => new RedisManagerPool(connString));

Then to enable in templates register TemplateRedisFilters:

var context = new TemplateContext { 
    TemplateFilters = {
        new TemplateRedisFilters()
    }
}.Init();

Your templates are now able to use the available Redis Filters.

redisCall

This is your main interface into Redis which utilizes the Custom Commands API to be able to execute any arbitrary Redis command. It can either be called with a string similar to commands sent with redis-cli, e.g:

{{ 'GET foo' | redisCall }}

This works for most Redis commands but uses internal heuristics to determine where to split the command into the multiple arguments that redis-server natively understands. A more deterministic usage which doesn't rely on any heuristics is to pass an array of arguments:

{{ ['GET', 'foo'] | redisCall }}

redisCall returns either a single object for redis commands returning single values or a List or nested List of objects for Redis commands returning complex Responses.

redisInfo

Returns the Redis Server Info from Redis Info command in a String Dictionary.

redisSearchKeys

Provides an efficient API for searching Redis Keys by utilizing Redis's non-blocking SCAN command, to fetch results and a server-side LUA script to populate the results with metadata. Results are returned in a typed List<RedisSearchResult>:

public class RedisSearchResult
{
    public string Id { get; set; }
    public string Type { get; set; }
    public long Ttl { get; set; }
    public long Size { get; set; }
}

redisSearchKeysAsJson

If preferred, you can access the search results as JSON and parse it on the client instead.

redisConnection

Returns the current Connection Info in an Object Dictionary containing: {{ host, port, db }}

redisToConnectionString

Converts an redisConnection Object Dictionary into a Redis Connection String.

Redis App Examples

The Web Apps below utilize Redis Filters for all their Redis functionality:

Redis Vue

redis.web-app.io is a generic Redis Database Viewer that provides a human-friendly view of any Redis data Type, including a dedicated UI to create and populate any Redis data type which just utilizes the above Redis Filters and a single Vue index.html App to power the Redis UI:

.NET Core Redis Viewer

Redis HTML

redis-html.web-app.io is a version of Redis UI built using just Templates and Redis filters where all functionality is maintained in a single index.html weighing under <200 LOC including HTML and JavaScript. It's a good example of how the declarative style of programming that ServiceStack Templates encourages a highly-readable code-base that packs a lot of functionality in a tiny foot print.

Server Generated HTML

It's not immediatly obvious when running this locally since both Templates and Redis are super fast, but Redis HTML was developed as a traditional Website where all HTML is server-generated and every search box key stroke and click on search results performs a full-page reload. There's a slight sub-second delay that causes a noticable flicker when hosted on the Internet due to network lag, but otherwise server-generated Template Websites can enable a highly responsive UI (especially in Intranets) with great SEO and deep-linking and back-button support working as expected without the complexity of adopting a client-side JavaScript SPA framework and build-system.

Run against your local Redis instance

You can run the above Redis WebApp's against your local redis instance by cloning the NetCoreApps/WebApp GitHub project and in the /src/apps folder run:

dotnet web/app.dll ../redis/web.settings

As this is a Web Template Web App it doesn't need any compilation so after running the Redis Web App you can modify the source code and see changes in real-time thanks to its built-in Hot Reloading support.

Populate redis with the Northwind database

You can use the northwind-data project to populate a Redis instance with Northwind test data by running:

dotnet run redis localhost:6379

See the Filters API Reference for the full list of Redis filters available.

made with by ServiceStack