Redis Lite is a small, simple redis client for .NET (Standard). It implements the often used redis commands, and then some.
Create an AsyncRedisClient
and connect it to the redis server of your choosing:
using(var client = new AsyncRedisClient())
{
var connectionSettings = new ConnectionSettings(address: "127.0.0.1", port: 6379);
await client.Connect(connectionSettings);
Then you can start commanding:
await client.Set("MyKey", "MyValue");
var result = await client.Get("MyKey");
await client.Del("MyKey");
...
}
Subscribing to redis channels is done through a special client, the AsyncRedisSubscriptionClient
:
// Create a client and connect to a server:
var subscriber = new AsyncRedisSubscriptionClient();
var connectionSettings = new ConnectionSettings(address: "127.0.0.1", port: 6379);
await subscriber.Connect(connectionSettings);
// Register callcback for subscription:
subscriber.OnMessageReceived += (channel, message) =>
{
// Do something when a message arrives.
};
// Subscribe to the channel you wish to recieve messages from:
subscriber.Subscribe("MyChannel");
Sending messages to a channel is done through the regular AsyncRedisClient
:
// Create a client and connect to a server:
var publisher = new AsyncRedisClient();
var connectionSettings = new ConnectionSettings(address: "127.0.0.1", port: 6379);
await publisher.Connect(connectionSettings);
// Publish a message to a given channel:
await publisher.Publish("MyChannel", "My interesting message");
The list of included redis commands can be seen here: RedisCommands.cs