Skip to content

pepelev/Rediska

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

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 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 implements IDisposable interface, instead factory.CreateAsync() returns a Resource<Connection> that does. This resource tracks underlying TcpClient. So you need to disponse 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 - binary safe string. This kind of reply represented with the class BulkString. If you are sure that reply contains a number you can get it's value as follows

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

Project status

The project currently in active development stage.

About

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

Topics

Resources

License

Stars

Watchers

Forks