Skip to content

Rediska is a Redis client for .NET with a focus on flexibility and extensibility.

License

Notifications You must be signed in to change notification settings

pepelev/Rediska

Repository files navigation

Rediska

Rediska is Redis client for .NET with a focus on flexibility and extensibility.

Rediska

Features

Plans (not implemented yet)

Getting started

Install NuGet package using Package Manager

Install-Package Rediska -Version 0.1.0

Show me the code

The types are in the following namespaces

using Rediska;
using Rediska.Commands.Strings;
var factory = new SimpleConnectionFactory();
var endPoint = new IPEndPoint(IPAddress.Loopback, 6379);
using (var connectionResource = await factory.CreateAsync(endPoint))
{
    var connection = connectionResource.Value;

    var set = new SET("users:12:score", "50");
    await connection.ExecuteAsync(set);
    var incr = new INCR("users:12:score");
    await connection.ExecuteAsync(incr);
    var get = new GET("users:12:score");
    var userScore = await connection.ExecuteAsync(get); // 51
}

To interact with Redis server you need a Connection. You can get one using a factory. In Rediska, each command is represented by a separate class, so to run a command you need to instantiate it and then execute using the connection.

Resource management

The Connection class does not implement IDisposable interface, instead factory.CreateAsync() returns a Resource<Connection> that does. This resource tracks underlying TcpClient. So you need to dispose the resource when the connection is no longer needed.

This approach clearly defines who owns the resource.

A note about the type of userScore

The GET command replies with a bulk string - safe binary string. This kind of reply is represented with the class BulkString. If you are sure that reply contains a number you can get its value as follows

var number = long.Parse(userScore.ToString())

Project status

The project is currently under active development.

About

Rediska is a Redis client for .NET with a focus on flexibility and extensibility.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages