Giter Club home page Giter Club logo

a-sync-redisclient's Introduction

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

a-sync-redisclient's People

Contributors

asos-tomlonghurst avatar codacy-badger avatar thomhurst avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.