/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合的并集。 /// </summary> /// <param name="keys">所有合并的集合名称</param> /// <returns></returns> public string[] SetUnion(string[] keys) { var redisKeys = Array.ConvertAll <string, RedisKey>(keys, m => (RedisKey)m); var list = RedisManager.ReadDataBase().SetCombine(SetOperation.Union, redisKeys); return(Array.ConvertAll <RedisValue, string>(list, m => m.ToString())); }
/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合之间的差集。 /// </summary> /// <param name="first"></param> /// <param name="second"></param> /// <returns></returns> public ArrayList SetDiff(string first, string second) { var list = RedisManager.ReadDataBase().SetCombine(SetOperation.Difference, first, second); ArrayList list_result = new ArrayList(); for (int i = 0; i < list.Count(); i++) { list_result.Add(list[i]); } return(list_result); }
/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合之间的交集。 /// </summary> /// <param name="first"></param> /// <param name="second"></param> /// <returns></returns> public ArrayList SetInter(string first, string second) { var list = RedisManager.ReadDataBase().SetCombine(SetOperation.Intersect, first, second); ArrayList list_result = new ArrayList(); for (int i = 0; i < list.Length; i++) { list_result.Add(list[i]); } return(list_result); }
/// <summary> /// 获取集合里面所有的key /// </summary> /// <param name="key">集合名称</param> /// <returns></returns> public ArrayList SetMembers(string key) { var sets = RedisManager.ReadDataBase().SetMembers(key); ArrayList list = new ArrayList(); foreach (var item in sets) { list.Add(item.ToString()); } return(list); }
/// <summary> /// 随机获取集合中的一组元素 /// </summary> /// <param name="key">集合名称</param> /// <param name="count">取出元素的个数</param> /// <returns></returns> public ArrayList SetRandMembers(string key, int count) { var list = RedisManager.ReadDataBase().SetRandomMembers(key, count); ArrayList list_result = new ArrayList(); for (int i = 0; i < list.Count(); i++) { list_result.Add(list[i]); } return(list_result); }
/// <summary> /// 从列表中获取指定范围的元素 /// </summary> /// <param name="key">列表名称</param> /// <param name="start">起始下标</param> /// <param name="stop">结束下标</param> /// <returns></returns> public ArrayList ListRange(string key, int start, int stop) { var list = RedisManager.ReadDataBase().ListRange(key, start, stop); var result_list = new ArrayList(); foreach (var item in list) { result_list.Add(item); } return(result_list); }
/// <summary> /// 迭代集合键中的元素 /// </summary> /// <param name="key">集合名称</param> /// <param name="pattern">获取的值</param> /// <param name="pagesize">最大结果数</param> /// <returns></returns> public List <Dictionary <string, string> > SortedSetScan(string key, string pattern, int pagesize, int cursor) { List <Dictionary <string, string> > list_result = new List <Dictionary <string, string> >(); var list = RedisManager.ReadDataBase().SortedSetScan(key, pattern, pagesize, cursor).ToArray(); for (int i = 0; i < list.Length; i++) { Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("member", list[i].Element); dict.Add("score", list[i].Score.ToString()); list_result.Add(dict); } return(list_result); }
/// <summary> /// 返回有序集 key 中,指定区间内的成员。 /// </summary> /// <param name="key"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public List <Dictionary <string, string> > SortedSetRangeWithScore(string key, int start, int end) { var list = RedisManager.ReadDataBase().SortedSetRangeByRankWithScores(key, start, end); List <Dictionary <string, string> > list_result = new List <Dictionary <string, string> >(); for (int i = 0; i < list.Count(); i++) { Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("member", list[i].Element); dict.Add("score", list[i].Score.ToString()); list_result.Add(dict); } return(list_result); }
/// <summary> /// 获取所有指定key的value,对于不存在的string或者不存在的key,返回null /// </summary> /// <param name="keys"></param> public ArrayList StringGet(string[] keys) { RedisKey[] list = new RedisKey[keys.Length]; for (int i = 0; i < keys.Length; i++) { list[i] = keys[i]; } var sets = RedisManager.ReadDataBase().StringGet(list); ArrayList list_result = new ArrayList(); foreach (var item in sets) { list_result.Add(item.ToString()); } return(list_result); }
/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合之间的交集。 /// </summary> /// <param name="keys"></param> /// <returns></returns> public ArrayList SetInter(string[] keys) { List <RedisKey> list_key = new List <RedisKey>(); for (int i = 0; i < keys.Length; i++) { list_key.Add(keys[i]); } var list = RedisManager.ReadDataBase().SetCombine(SetOperation.Intersect, list_key.ToArray()); ArrayList list_result = new ArrayList(); for (int i = 0; i < list.Length; i++) { list_result.Add(list[i]); } return(list_result); }
/// <summary> /// 查看给定键距离过期键有多少秒 /// </summary> /// <param name="key"></param> /// <returns></returns> public double KeyTTL(string key) { var flag = RedisManager.ReadDataBase().KeyExists(key); if (!flag) { return(-2); } var time = RedisManager.ReadDataBase().KeyTimeToLive(key); if (time == null) { return(-1); } else { return(time.Value.TotalSeconds); } }
/// <summary> /// 迭代集合键中的元素 /// </summary> /// <param name="key">集合名称</param> /// <param name="pattern">获取的值</param> /// <param name="pagesize">最大结果数</param> /// <returns></returns> public string[] SetScan(string key, string pattern, int pagesize, int cursor) { var list = RedisManager.ReadDataBase().SetScan(key, pattern, pagesize, cursor).ToArray(); return(Array.ConvertAll <RedisValue, string>(list, m => m.ToString())); }
/// <summary> /// 但它将结果保存到 destination 集合,该集合是所有给定集合的并集。 /// </summary> /// <param name="destination">合并生成的集合</param> /// <param name="keys">所有合并的集合名称</param> /// <returns></returns> public long SetUnionStore(string destination, string[] keys) { var redisKeys = Array.ConvertAll <string, RedisKey>(keys, m => (RedisKey)m); return(RedisManager.ReadDataBase().SetCombineAndStore(SetOperation.Union, destination, redisKeys)); }
/// <summary> /// 但它将结果保存到 destination 集合,该集合是所有给定集合的并集。 /// </summary> /// <param name="destination">合并生成的集合</param> /// <param name="first">第一个集合</param> /// <param name="second">第二个集合</param> /// <returns></returns> public long SetUnionStore(string destination, string first, string second) { return(RedisManager.ReadDataBase().SetCombineAndStore(SetOperation.Union, destination, first, second)); }
/// <summary> /// 返回有序集 key 中,指定区间内的成员。 /// </summary> /// <param name="key"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public string[] SortedSetRevRange(string key, int start, int end) { var list = RedisManager.ReadDataBase().SortedSetRangeByRank(key, start, end, Order.Descending); return(Array.ConvertAll <RedisValue, string>(list, m => m.ToString())); }
/// <summary> /// 返回一个集合的全部成员,该集合是所有给定集合的并集。 /// </summary> /// <param name="first">第一个集合</param> /// <param name="second">第二个集合</param> /// <returns></returns> public string[] SetUnion(string first, string second) { var list = RedisManager.ReadDataBase().SetCombine(SetOperation.Union, first, second); return(Array.ConvertAll <RedisValue, string>(list, m => m.ToString())); }
/// <summary> /// 获取存储在key上的值的一个子字符串 /// </summary> /// <param name="key"></param> /// <param name="start">起始位置</param> /// <param name="end">结束位置</param> /// <remarks>返回key对应的字符串value的子串,这个子串是由start和end位移决定的(两者都在string内)。可以用负的位移来表示从string尾部开始数的下标。所以-1就是最后一个字符,-2就是倒数第二个,以此类推。</remarks> /// <returns></returns> public string StringGetRange(string key, int start, int end) { return(RedisManager.ReadDataBase().StringGetRange(key, start, end)); }
/// <summary> /// 返回集合的基数 /// </summary> /// <param name="key">集合名称</param> /// <returns></returns> public long SetLength(string key) { return(RedisManager.ReadDataBase().SetLength(key)); }
/// <summary> /// 判断成员是否是集合中的成员 /// </summary> /// <param name="key">集合名称</param> /// <param name="member">成员的值</param> /// <returns></returns> public bool SetContains(string key, string member) { return(RedisManager.ReadDataBase().SetContains(key, member)); }
/// <summary> /// 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 /// </summary> /// <param name="key"></param> /// <param name="member"></param> /// <returns></returns> public long?SortedSetRank(string key, string member) { return(RedisManager.ReadDataBase().SortedSetRank(key, member)); }
/// <summary> /// 返回有序集 key 中,成员 member 的 score 值。 /// </summary> /// <param name="key"></param> /// <param name="member"></param> /// <returns></returns> public double?SortedSetScore(string key, string member) { return(RedisManager.ReadDataBase().SortedSetScore(key, member)); }
/// <summary> /// 返回key的value /// </summary> /// <param name="keys"></param> /// <remarks>返回key的value。如果key不存在,返回特殊值nil。如果key的value不是string,就返回错误,因为GET只处理string类型的values。</remarks> /// <returns>key对应的value,或者nil(key不存在时)</returns> public string StringGet(string key) { return(RedisManager.ReadDataBase().StringGet(key)); }
/// <summary> /// 返回key的value /// </summary> /// <param name="keys"></param> /// <remarks>返回key的value。如果key不存在,返回特殊值nil。如果key的value不是string,就返回错误,因为GET只处理string类型的values。</remarks> /// <returns>key对应的value,或者nil(key不存在时)</returns> public string StringGetAsync(string key) { return(RedisManager.ReadDataBase().StringGetAsync(key).Result); }
/// <summary> /// 判断Key是否存在 /// </summary> /// <param name="key"></param> /// <returns></returns> public bool KeyExists(string key) { return(RedisManager.ReadDataBase().KeyExists(key)); }
/// <summary> /// 查看哈希表 key 中,给定域 field 是否存在。 /// </summary> /// <param name="key">哈希表的名称</param> /// <param name="field">域的名称</param> /// <returns></returns> public bool HashExists(string key, string field) { return(RedisManager.ReadDataBase().HashExists(key, field)); }
/// <summary> /// 随机获取集合中的一个元素 /// </summary> /// <param name="key">集合名称</param> /// <returns></returns> public string SetRandMember(string key) { return(RedisManager.ReadDataBase().SetRandomMember(key)); }
/// <summary> /// 返回哈希表 key 中给定域 field 的值。 /// </summary> /// <param name="key">哈希表的名称</param> /// <param name="field">域的名称</param> /// <returns></returns> public string HashGet(string key, string field) { return(RedisManager.ReadDataBase().HashGet(key, field)); }
/// <summary> /// 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序。 /// </summary> /// <param name="key"></param> /// <param name="member"></param> /// <returns></returns> public long?SortedSetRevRank(string key, string member) { return(RedisManager.ReadDataBase().SortedSetRank(key, member, Order.Descending)); }
/// <summary> /// 返回哈希表 key 中,所有的域和值。 /// </summary> /// <param name="key">哈希表的名称</param> /// <returns></returns> public Dictionary <string, string> HashGetAll(string key) { var entry = RedisManager.ReadDataBase().HashGetAll(key); return(entry.ToDictionary(m => m.Name.ToString(), n => n.Value.ToString())); }
/// <summary> /// 获取指定下标的元素 /// </summary> /// <param name="key"></param> /// <param name="index"></param> /// <returns></returns> public string ListIndex(string key, int index) { return(RedisManager.ReadDataBase().ListGetByIndex(key, index)); }