pairbit / it.redis.entity Goto Github PK
View Code? Open in Web Editor NEWObject mapping for Redis
License: MIT License
Object mapping for Redis
License: MIT License
Add operator in TEntity
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))
class MyEntity
{
public byte[]? RedisKey { get; set; }
public string Name { get; set; }
}
var entity = new MyEntity()
db.EntitySet(entity)
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; }
}
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));
}
If char to byte
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.