Rediska is Redis client for .NET with a focus on flexibility and extensibility.
- Keys, Strings, Transactions, Sets, Server, Lists, HyperLogLog, Hashes and Streams commands
- Async API
- Easy way to handle command response differently
- Easy way to write custom commands, e.g. for Redis modules
- RESP 2 support - allows to build a proxy
- Full set of commands
- Pipelining
- Pub/Sub
- Redis Cluster
- Redis Client Side Caching
Install NuGet package using Package Manager
Install-Package Rediska -Version 0.1.0
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.
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.
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())
The project is currently under active development.