Skip to content

karayakar/A-sync-RedisClient

 
 

Repository files navigation

A[sync]RedisClient

nuget Codacy Badge

Install

Install via Nuget > Install-Package TomLonghurst.RedisClient

Usage

Connect

Create a RedisClientConfig object:

var config = new RedisClientConfig(Host, Port, Password) {
  Ssl = true, 
  Timeout = 5000
  };

Create a new RedisClientManager object:

int poolSize = 5;
var redisManager = new RedisClientManager(config, poolSize);

Call RedisClientManager.GetRedisClientAsync()

var client = await redisManager.GetRedisClientAsync();

Pool Size

Each Redis Client can only perform one operation at a time. Because it's usually very fast, one is enough for most applications. However if your application takes heavy traffic, and you are seeing RedisTimeoutExceptions then consider upping the pool size.

Commands

Ping

var ping = await client.Ping();

Set

await _client.StringSetAsync("key", "123", AwaitOptions.FireAndForget);

Set with TimeToLive

await _client.StringSetAsync("key", "123", 120, AwaitOptions.FireAndForget);

Multi Set

var keyValues = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("key1", "1"),
                new KeyValuePair<string, string>("key2", "2"),
                new KeyValuePair<string, string>("key3", "3")
            };
await _client.StringSetAsync(keyValues, AwaitOptions.AwaitCompletion);

Get

var value = await _client.StringGetAsync("key");

Multi Get

var values = await _client.StringGetAsync(new [] { "key1", "key2" });

Delete

await _client.DeleteKeyAsync("key", AwaitOptions.AwaitCompletion);

Multi Delete

await _client.DeleteKeyAsync(new [] { "key1", "key2" }, AwaitOptions.AwaitCompletion);

Key Exists

var exists = await _client.KeyExistsAsync("key");

AwaitOptions

Any method taking an AwaitOptions parameter has two options:

AwaitCompletion

Wait for the operation to complete on the Redis server before resuming program execution

FireAndForget

Resume with program execution instantly and forget about checking the result

If you enjoy, please buy me a coffee :)

Buy Me A Coffee

About

An asynchronous Redis Client for .NET!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%