Git Product home page Git Product logo

it.redis.entity's People

Contributors

pairbit avatar

Watchers

 avatar

it.redis.entity's Issues

Add WriteKey to Writer

void WriteKey<TKey>(in TEntity entity, in TKey key)

Add extension

TEntity? EntityGet<TEntity, TKey>(in TKey key)

For example

var id = Guid.NewGuid()
db.EntityGet<Document, Guid>(in id)

int index = 1;
db.EntityGet<Document, (Guid, int)>(in (id, index))

Check inheritance RedisKey and RedisKeyBits

abstract class RedisEntity {
private byte[]? _redisKey;
private byte _redisKeyBits;
}

class MyEntity : RedisEntity {
public string? Data { get; set; }
}

and

interface IRedisEntity {
byte[]? RedisKey { get; set; }
byte RedisKeyBits { get; set; }
}

interface IMyEntity : IRedisEntity {
string Name { get; set; }
}

add new extensions

public static class xIRedisEntityReader
{
    public static void ReadNew<T>(this IRedisEntityReader<T> reader, HashEntry[] entries, T entity, RedisValue[] fields, int offset = 0)
    {
        if (entries == null) throw new ArgumentNullException(nameof(entries));
        if (fields == null) throw new ArgumentNullException(nameof(fields));
        if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset));
        if (entries.Length < fields.Length + offset) throw new ArgumentOutOfRangeException(nameof(entries));

        for (int i = 0; i < fields.Length; i++)
        {
            var field = fields[i];
            var value = reader.Read(entity, in field);

            entries[i + offset] = new HashEntry(field, value);
        }
    }

    public static void ReadNew<T>(this IRedisEntityReader<T> reader, HashEntry[] entries, T entity, int offset = 0)
        => reader.ReadNew(entries, entity, reader.Fields.All, offset);

    public static RedisValue Serialize<TEntity, TField>(this IRedisEntityReader<TEntity> reader, in RedisValue field, in TField value)
        => reader.GetSerializer<TField>(in field).Serialize(in value);

    public static HashEntry SerializeToHashEntry<TEntity, TField>(this IRedisEntityReader<TEntity> reader, in RedisValue field, in TField value)
        => new(field, reader.GetSerializer<TField>(in field).Serialize(in value));
}

add support nullable struct to EntityGetFieldAsync

public static async Task<TField?> EntityGetFieldStructAsync<TEntity, TField>(
        this IDatabaseAsync db, RedisKey key, RedisValue field,
        IRedisEntityWriter<TEntity>? writer = null, CommandFlags flags = CommandFlags.None)
        where TField : struct
    {
        var redisValue = await db.HashGetAsync(key, field, flags).ConfigureAwait(false);
        if (redisValue.IsNull) return default;

        TField value = default;
        (writer ?? RedisEntity<TEntity>.Writer).GetDeserializer<TField>(in field).Deserialize(in redisValue, ref value);
        return value;
    }

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.