using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Permission.Redis { public interface IRedisService { #region String 操作 /// /// 设置 key 并保存字符串(如果 key 已存在,则覆盖值) /// /// /// /// /// bool StringSet(string redisKey, string redisValue, TimeSpan? expiry = null); /// /// 保存多个 Key-value /// /// /// bool StringSet(IEnumerable> keyValuePairs); /// /// 获取字符串 /// /// /// /// string StringGet(string redisKey, TimeSpan? expiry = null); /// /// 存储一个对象(该对象会被序列化保存) /// /// /// /// /// bool StringSet(string redisKey, T redisValue, TimeSpan? expiry = null); /// /// 获取一个对象(会进行反序列化) /// /// /// /// T StringGet(string redisKey, TimeSpan? expiry = null); #region String 异步操作 /// /// 保存一个字符串值 /// /// /// /// /// Task StringSetAsync(string redisKey, string redisValue, TimeSpan? expiry = null); /// /// 保存一组字符串值 /// /// /// Task StringSetAsync(IEnumerable> keyValuePairs); /// /// 获取单个值 /// /// /// /// /// Task StringGetAsync(string redisKey, string redisValue, TimeSpan? expiry = null); /// /// 存储一个对象(该对象会被序列化保存) /// /// /// /// /// Task StringSetAsync(string redisKey, T redisValue, TimeSpan? expiry = null); /// /// 获取一个对象(会进行反序列化) /// /// /// /// Task StringGetAsync(string redisKey, TimeSpan? expiry = null); #endregion async #endregion #region Hash 操作 /// /// 判断该字段是否存在 hash 中 /// /// /// /// bool HashExists(string redisKey, string hashField); /// /// 从 hash 中移除指定字段 /// /// /// /// bool HashDelete(string redisKey, string hashField); /// /// 从 hash 中移除指定字段 /// /// /// /// long HashDelete(string redisKey, IEnumerable hashFields); /// /// 在 hash 设定值 /// /// /// /// /// bool HashSet(string redisKey, string hashField, string value); /// /// 在 hash 中设定值 /// /// /// void HashSet(string redisKey, IEnumerable> hashFields); /// /// 在 hash 中获取值 /// /// /// /// string HashGet(string redisKey, string hashField); /// /// 在 hash 中获取值 /// /// /// /// IEnumerable HashGet(string redisKey, IEnumerable hashFields); /// /// 从 hash 返回所有的字段值 /// /// /// IEnumerable HashKeys(string redisKey); /// /// 返回 hash 中的所有值 /// /// /// IEnumerable HashValues(string redisKey); /// /// 在 hash 设定值(序列化) /// /// /// /// /// bool HashSet(string redisKey, string hashField, T redisValue); /// /// 在 hash 中获取值(反序列化) /// /// /// /// T HashGet(string redisKey, string hashField); #region Hash 异步操作 /// /// 判断该字段是否存在 hash 中 /// /// /// /// Task HashExistsAsync(string redisKey, string hashField); /// /// 从 hash 中移除指定字段 /// /// /// /// Task HashDeleteAsync(string redisKey, string hashField); /// /// 从 hash 中移除指定字段 /// /// /// /// Task HashDeleteAsync(string redisKey, IEnumerable hashFields); /// /// 在 hash 设定值 /// /// /// /// /// Task HashSetAsync(string redisKey, string hashField, string value); /// /// 在 hash 中设定值 /// /// /// Task HashSetAsync(string redisKey, IEnumerable> hashFields); /// /// 在 hash 中获取值 /// /// /// /// Task HashGetAsync(string redisKey, string hashField); /// /// 在 hash 中获取值 /// /// /// /// /// Task> HashGetAsync(string redisKey, IEnumerable hashFields, string value); /// /// 从 hash 返回所有的字段值 /// /// /// Task> HashKeysAsync(string redisKey); /// /// 返回 hash 中的所有值 /// /// /// Task> HashValuesAsync(string redisKey); /// /// 在 hash 设定值(序列化) /// /// /// /// /// Task HashSetAsync(string redisKey, string hashField, T value); /// /// 在 hash 中获取值(反序列化) /// /// /// /// Task HashGetAsync(string redisKey, string hashField); #endregion #endregion #region List 操作 /// /// 移除并返回存储在该键列表的第一个元素 /// /// /// string ListLeftPop(string redisKey); /// /// 移除并返回存储在该键列表的最后一个元素 /// /// /// string ListRightPop(string redisKey); /// /// 移除列表指定键上与该值相同的元素 /// /// /// /// long ListRemove(string redisKey, string redisValue); /// /// 在列表尾部插入值。如果键不存在,先创建再插入值 /// /// /// /// long ListRightPush(string redisKey, string redisValue); /// /// 在列表头部插入值。如果键不存在,先创建再插入值 /// /// /// /// long ListLeftPush(string redisKey, string redisValue); /// /// 返回列表上该键的长度,如果不存在,返回 0 /// /// /// long ListLength(string redisKey); /// /// 返回在该列表上键所对应的元素 /// /// /// /// /// IEnumerable ListRange(string redisKey, long start = 0L, long stop = -1L); /// /// 移除并返回存储在该键列表的第一个元素 /// /// /// T ListLeftPop(string redisKey); /// /// 移除并返回存储在该键列表的最后一个元素 /// /// /// T ListRightPop(string redisKey); /// /// 在列表尾部插入值。如果键不存在,先创建再插入值 /// /// /// /// long ListRightPush(string redisKey, T redisValue); /// /// 在列表头部插入值。如果键不存在,先创建再插入值 /// /// /// /// long ListLeftPush(string redisKey, T redisValue); #region List 异步操作 /// /// 移除并返回存储在该键列表的第一个元素 /// /// /// Task ListLeftPopAsync(string redisKey); /// /// 移除并返回存储在该键列表的最后一个元素 /// /// /// Task ListRightPopAsync(string redisKey); /// /// 移除列表指定键上与该值相同的元素 /// /// /// /// Task ListRemoveAsync(string redisKey, string redisValue); /// /// 在列表尾部插入值。如果键不存在,先创建再插入值 /// /// /// /// Task ListRightPushAsync(string redisKey, string redisValue); /// /// 在列表头部插入值。如果键不存在,先创建再插入值 /// /// /// /// Task ListLeftPushAsync(string redisKey, string redisValue); /// /// 返回列表上该键的长度,如果不存在,返回 0 /// /// /// Task ListLengthAsync(string redisKey); /// /// 返回在该列表上键所对应的元素 /// /// /// /// /// Task> ListRangeAsync(string redisKey, long start = 0L, long stop = -1L); /// /// 移除并返回存储在该键列表的第一个元素 /// /// /// Task ListLeftPopAsync(string redisKey); /// /// 移除并返回存储在该键列表的最后一个元素 /// /// /// Task ListRightPopAsync(string redisKey); /// /// 在列表尾部插入值。如果键不存在,先创建再插入值 /// /// /// /// Task ListRightPushAsync(string redisKey, T redisValue); /// /// 在列表头部插入值。如果键不存在,先创建再插入值 /// /// /// /// Task ListLeftPushAsync(string redisKey, T redisValue); #endregion #endregion #region SortedSet 操作 /// /// SortedSet 新增 /// /// /// /// /// bool SortedSetAdd(string redisKey, string member, double score); /// /// 在有序集合中返回指定范围的元素,默认情况下从低到高。 /// /// /// /// /// /// IEnumerable SortedSetRangeByRank(string redisKey, long start = 0L, long stop = -1L, OrderType order = OrderType.Ascending); /// /// 返回有序集合的元素个数 /// /// /// long SortedSetLength(string redisKey); /// /// 返回有序集合的元素个数 /// /// /// /// bool SortedSetLength(string redisKey, string memebr); /// /// SortedSet 新增 /// /// /// /// /// bool SortedSetAdd(string redisKey, T member, double score); /// /// 增量的得分排序的集合中的成员存储键值键按增量 /// /// /// /// /// double SortedSetIncrement(string redisKey, string member, double value = 1); #region SortedSet 异步操作 /// /// SortedSet 新增 /// /// /// /// /// Task SortedSetAddAsync(string redisKey, string member, double score); /// /// 在有序集合中返回指定范围的元素,默认情况下从低到高。 /// /// /// Task> SortedSetRangeByRankAsync(string redisKey); /// /// 返回有序集合的元素个数 /// /// /// Task SortedSetLengthAsync(string redisKey); /// /// 返回有序集合的元素个数 /// /// /// /// Task SortedSetRemoveAsync(string redisKey, string memebr); /// /// SortedSet 新增 /// /// /// /// /// Task SortedSetAddAsync(string redisKey, T member, double score); /// /// 增量的得分排序的集合中的成员存储键值键按增量 /// /// /// /// /// Task SortedSetIncrementAsync(string redisKey, string member, double value = 1); #endregion #endregion #region key 操作 /// /// 移除指定 Key /// /// /// bool KeyDelete(string redisKey); /// /// 移除指定 Key /// /// /// long KeyDelete(IEnumerable redisKeys); /// /// 校验 Key 是否存在 /// /// /// bool KeyExists(string redisKey); /// /// 重命名 Key /// /// /// /// bool KeyRename(string redisKey, string redisNewKey); /// /// 设置 Key 的时间 /// /// /// /// bool KeyExpire(string redisKey, TimeSpan? expiry); #region key 异步操作 /// /// 移除指定 Key /// /// /// Task KeyDeleteAsync(string redisKey); /// /// 移除指定 Key /// /// /// Task KeyDeleteAsync(IEnumerable redisKeys); /// /// 校验 Key 是否存在 /// /// /// Task KeyExistsAsync(string redisKey); /// /// 重命名 Key /// /// /// /// Task KeyRenameAsync(string redisKey, string redisNewKey); /// /// 设置 Key 的时间 /// /// /// /// Task KeyExpireAsync(string redisKey, TimeSpan? expiry); #endregion #endregion } }