// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using StackExchange.Redis; namespace EpicGames.Redis { /// /// Redis hash, with members corresponding to the property names of a type /// public record struct RedisHash(IDatabaseAsync Database, RedisHashKey Key); /// /// Redis hash, with members of the given key and value types /// public record struct RedisHash(IDatabaseAsync Database, RedisHashKey Key); /// /// Extension methods for hashes /// public static class RedisHashExtensions { #region Conditions /// public static Condition HashEqual(this RedisHash target, Expression> selector, TValue value) => target.Key.HashEqual(selector, value); /// public static Condition HashEqual(this RedisHash target, TName name, TValue value) => target.Key.HashEqual(name, value); /// public static Condition HashExists(this RedisHash target, Expression> selector) => target.Key.HashExists(selector); /// public static Condition HashExists(this RedisHash target, TName name) => target.Key.HashExists(name); /// public static Condition HashLengthEqual(this RedisHash target, long length) => target.Key.HashLengthEqual(length); /// public static Condition HashLengthGreaterThan(this RedisHash target, long length) => target.Key.HashLengthGreaterThan(length); /// public static Condition HashLengthLessThan(this RedisHash target, long length) => target.Key.HashLengthLessThan(length); /// public static Condition HashNotExists(this RedisHash target, Expression> selector) => target.Key.HashNotExists(selector); /// public static Condition HashNotExists(this RedisHash target, TName name) => target.Key.HashNotExists(name); /// public static Condition HashNotEqual(this RedisHash target, Expression> selector, TValue value) => target.Key.HashNotEqual(selector, value); /// public static Condition HashNotEqual(this RedisHash target, TName name, TValue value) => target.Key.HashNotEqual(name, value); #endregion #region HashDecrementAsync /// public static Task DecrementAsync(this RedisHash target, Expression> selector, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.HashDecrementAsync(target.Key, selector, value, flags); /// public static Task DecrementAsync(this RedisHash target, Expression> selector, double value = 1.0, CommandFlags flags = CommandFlags.None) => target.Database.HashDecrementAsync(target.Key, selector, value, flags); /// public static Task DecrementAsync(this RedisHash target, TName name, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.HashDecrementAsync(target.Key, name, value, flags); /// public static Task DecrementAsync(this RedisHash target, TName name, double value = 1.0, CommandFlags flags = CommandFlags.None) => target.Database.HashDecrementAsync(target.Key, name, value, flags); #endregion #region HashDeleteAsync /// public static Task DeleteAsync(this RedisHash target, Expression> selector, CommandFlags flags = CommandFlags.None) => target.Database.HashDeleteAsync(target.Key, selector, flags); /// public static Task DeleteAsync(this RedisHash target, TName name, CommandFlags flags = CommandFlags.None) => target.Database.HashDeleteAsync(target.Key, name, flags); /// public static Task DeleteAsync(this RedisHash target, TName[] names, CommandFlags flags = CommandFlags.None) => target.Database.HashDeleteAsync(target.Key, names, flags); #endregion #region HashExistsAsync /// public static Task ExistsAsync(this RedisHash target, TName name, CommandFlags flags = CommandFlags.None) => target.Database.HashExistsAsync(target.Key, name, flags); #endregion #region HashGetAsync /// public static Task GetAsync(this RedisHash target, Expression> selector, CommandFlags flags = CommandFlags.None) => target.Database.HashGetAsync(target.Key, selector, flags); /// public static Task GetAsync(this RedisHash target, TName name, CommandFlags flags = CommandFlags.None) => target.Database.HashGetAsync(target.Key, name, flags); /// public static Task GetAsync(this RedisHash target, TName[] names, CommandFlags flags = CommandFlags.None) => target.Database.HashGetAsync(target.Key, names, flags); #endregion #region HashGetAllAsync /// public static Task[]> GetAllAsync(this RedisHash target, CommandFlags flags = CommandFlags.None) => target.Database.HashGetAllAsync(target.Key, flags); #endregion #region HashIncrementAsync /// public static Task IncrementAsync(this RedisHash target, Expression> selector, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.HashIncrementAsync(target.Key, selector, value, flags); /// public static Task IncrementAsync(this RedisHash target, Expression> selector, double value = 1.0, CommandFlags flags = CommandFlags.None) => target.Database.HashIncrementAsync(target.Key, selector, value, flags); /// public static Task IncrementAsync(this RedisHash target, TName name, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.HashIncrementAsync(target.Key, name, value, flags); /// public static Task IncrementAsync(this RedisHash target, TName name, double value = 1.0, CommandFlags flags = CommandFlags.None) => target.Database.HashIncrementAsync(target.Key, name, value, flags); #endregion #region HashKeysAsync /// public static Task KeysAsync(this RedisHash target, CommandFlags flags = CommandFlags.None) => target.Database.HashKeysAsync(target.Key, flags); #endregion #region HashLengthAsync /// public static Task LengthAsync(this RedisHash target, CommandFlags flags = CommandFlags.None) => target.Database.HashLengthAsync(target.Key, flags); #endregion #region HashScanAsync /// public static IAsyncEnumerable> ScanAsync(this RedisHash target, RedisValue pattern, int pageSize = 250, long cursor = 0, int pageOffset = 0, CommandFlags flags = CommandFlags.None) => target.Database.HashScanAsync(target.Key, pattern, pageSize, cursor, pageOffset, flags); #endregion #region HashSetAsync /// public static Task SetAsync(this RedisHash target, Expression> selector, TValue value, When when = When.Always, CommandFlags flags = CommandFlags.None) => target.Database.HashSetAsync(target.Key, selector, value, when, flags); /// public static Task SetAsync(this RedisHash target, TName name, TValue value, When when = When.Always, CommandFlags flags = CommandFlags.None) => target.Database.HashSetAsync(target.Key, name, value, when, flags); /// public static Task SetAsync(this RedisHash target, IEnumerable> entries, CommandFlags flags = CommandFlags.None) => target.Database.HashSetAsync(target.Key, entries, flags); #endregion #region HashValuesAsync /// public static Task ValuesAsync(this RedisHash target, CommandFlags flags = CommandFlags.None) => target.Database.HashValuesAsync(target.Key, flags); #endregion } }