// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Threading.Tasks; using StackExchange.Redis; namespace EpicGames.Redis { /// /// Accessor for a typed Redis string /// /// Database to operate on /// Key for the string /// Type of element stored in the string public record struct RedisString(IDatabaseAsync Database, RedisStringKey Key); /// /// Extension methods for strings /// public static class RedisStringExtensions { #region Conditions /// public static Condition StringEqual(this RedisString target, TElement value) => target.Key.StringEqual(value); /// public static Condition StringLengthEqual(this RedisString target, long length) => target.Key.StringLengthEqual(length); /// public static Condition StringLengthGreaterThan(this RedisString target, long length) => target.Key.StringLengthGreaterThan(length); /// public static Condition StringLengthLessThan(this RedisString target, long length) => target.Key.StringLengthLessThan(length); /// public static Condition StringNotEqual(this RedisString target, TElement value) => target.Key.StringNotEqual(value); #endregion #region StringDecrementAsync /// public static Task StringDecrementAsync(this RedisString target, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.StringDecrementAsync(target.Key, value, flags); /// public static Task StringDecrementAsync(this RedisString target, double value = 1.0, CommandFlags flags = CommandFlags.None) => target.Database.StringDecrementAsync(target.Key, value, flags); #endregion #region StringGetAsync /// public static Task GetAsync(this RedisString target, CommandFlags flags = CommandFlags.None) => target.Database.StringGetAsync(target.Key, flags); /// public static Task GetAsync(this RedisString target, TValue defaultValue, CommandFlags flags = CommandFlags.None) => target.Database.StringGetAsync(target.Key, defaultValue, flags); #endregion #region StringIncrementAsync /// public static Task IncrementAsync(this RedisString target, long value = 1L, CommandFlags flags = CommandFlags.None) => target.Database.StringIncrementAsync(target.Key, value, flags); #endregion #region StringLengthAsync /// public static Task LengthAsync(this RedisString target, CommandFlags flags = CommandFlags.None) => target.Database.StringLengthAsync(target.Key, flags); #endregion #region StringSetAsync /// public static Task SetAsync(this RedisString target, TValue value, TimeSpan? expiry = null, When when = When.Always, CommandFlags flags = CommandFlags.None) => target.Database.StringSetAsync(target.Key, value, expiry, when, flags); #endregion } }