Giter Club home page Giter Club logo

cloudstructures's Introduction

CloudStructures

CloudStructures is the Redis client based on StackExchange.Redis.

StackExchange.Redis is very pure and low level library. It's Redis driver like ADO.NET. It's difficult to use it as raw. CloudStructures provides simple O/R (Object / Redis) mapper like Dapper for ADO.NET.

Releases

Support framework

  • .NET 5+
  • .NET Standard 2.0+
  • .NET Framework 4.6.1+

Installation

dotnet add package CloudStructures

Data structures of Redis

CloudStructures supports these Redis data types. All methods are async.

Structure Description
RedisBit Bits API
RedisDictionary<TKey, TValue> Hashes API with constrained value type
RedisGeo<T> Geometries API
RedisHashSet<T> like RedisDictionary<T, bool>
RedisHyperLogLog<T> HyperLogLogs API
RedisList<T> Lists API
RedisLua Lua eval API
RedisSet<T> Sets API
RedisSortedSet<T> SortedSets API
RedisString<T> Strings API

Getting started

Following code is simple sample.

// RedisConnection have to be held as static.
public static class RedisServer
{
    public static RedisConnection Connection { get; }
    public static RedisServer()
    {
        var config = new RedisConfig("name", "connectionString");
        Connection = new RedisConnection(config);
    }
}

// A certain data class
public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }
}

// 1. Create redis structure
var key = "test-key";
var defaultExpiry = TimeSpan.FromDays(1);
var redis = new RedisString<Person>(RedisServer.Connection, key, defaultExpiry)

// 2. Call command
var neuecc = new Person("neuecc", 35);
await redis.SetAsync(neuecc);
var result = await redis.GetAsync();

ValueConverter

If you use this library, you should implement IValueConverter to serialize your original class. Unless you pass custom IValueConverter to RedisConnection ctor, fallback to SystemTextJsonConverter automatically that is default converter we provide.

How to implement custom IValueConverter

using CloudStructures.Converters;
using Utf8Json;
using Utf8Json.Resolvers;

namespace HowToImplement_CustomValueConverter
{
    public sealed class Utf8JsonConverter : IValueConverter
    {
        public byte[] Serialize<T>(T value)
            => JsonSerializer.Serialize(value, StandardResolver.AllowPrivate);

        public T Deserialize<T>(byte[] value)
            => JsonSerializer.Deserialize<T>(value, StandardResolver.AllowPrivate);
    }
}
using CloudStructures.Converters;
using MessagePack;
using MessagePack.Resolvers;

namespace HowToImplement_CustomValueConverter
{
    public sealed class MessagePackConverter : IValueConverter
    {
        private MessagePackSerializerOptions Options { get; }

        public MessagePackConverter(MessagePackSerializerOptions options)
            => this.Options = options;

        public byte[] Serialize<T>(T value)
            => MessagePackSerializer.Serialize(value, this.Options);

        public T Deserialize<T>(byte[] value)
            => MessagePackSerializer.Deserialize<T>(value, this.Options);
    }
}

Authors

Yoshifumi Kawai is software developer in Tokyo, Japan. Awarded Microsoft MVP (C#) since April, 2011. He's the original owner of this project.

Takaaki Suzuki is software developer in Fukui, Japan. Awarded Microsoft MVP (C#) since July, 2012. He's a contributer who led the .NET Standard support.

License

This library is under the MIT License.

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.