public List <string> GetFilteredIdsByPropertyFromSets <T>(List <string> ids, string propertyName) where T : IRedisModelBase { using (var Redis = RedisClientManager.GetClient()) { string tempSetKey = string.Format("TempSet:{0}", Guid.NewGuid().ToString()); Redis.AddRangeToSet(tempSetKey, ids); var filteredIds = Redis.GetDifferencesFromSet(tempSetKey, RedisKeyFactory.QueryKeyWithProperty <T>(propertyName)).ToList(); Redis.Remove(tempSetKey); return(filteredIds); } }
public List <string> FindIdsByValueRange <T>(string propertyName, DateTime?start, DateTime?end) where T : IRedisModelBase { if (!start.HasValue) { start = DateTime.MinValue; } if (!end.HasValue) { end = DateTime.MaxValue; } using (var Redis = RedisClientManager.GetReadOnlyClient()) { return(Redis.GetRangeFromSortedSetByLowestScore(RedisKeyFactory.QueryKeyWithProperty <T>(propertyName), start.GetValueOrDefault().Ticks, end.GetValueOrDefault().Ticks)); } }
public List <string> GetIntersectIdsByPropertyFromSets <T>(List <string> ids, params string[] propertyName) where T : IRedisModelBase { using (var Redis = RedisClientManager.GetClient()) { string tempSetKey = string.Format("TempSet:{0}", Guid.NewGuid().ToString()); Redis.AddRangeToSet(tempSetKey, ids); List <string> keys = new List <string>(); foreach (var item in propertyName) { keys.Add(RedisKeyFactory.QueryKeyWithProperty <T>(item)); } keys.Add(tempSetKey); var filteredIds = Redis.GetIntersectFromSets(keys.ToArray()).ToList(); Redis.Remove(tempSetKey); return(filteredIds); } }
public List <string> GetPagedModelIds <T>(int pageNum, int pageSize, string propertyName = "", bool isAsc = false) where T : IRedisModelBase { using (var Redis = RedisClientManager.GetReadOnlyClient()) { int start = (pageNum - 1) * pageSize; int end = pageNum * pageSize - 1; if (pageNum == 0) // get all { start = 0; end = -1; } if (string.IsNullOrWhiteSpace(propertyName)) { if (isAsc) { return(Redis.GetRangeFromSortedSet(RedisKeyFactory.ListAllKeys <T>(), start, end)); } else { return(Redis.GetRangeFromSortedSetDesc(RedisKeyFactory.ListAllKeys <T>(), start, end)); } } else { string queryKey = RedisKeyFactory.QueryKeyWithProperty <T>(propertyName); if (isAsc) { return(Redis.GetRangeFromSortedSet(queryKey, start, end)); } else { return(Redis.GetRangeFromSortedSetDesc(queryKey, start, end)); } } } }
public List <string> GetSortedIdsByProperty <T>(List <string> ids, string propertyName, int startNum = 0, int num = 0, bool isDesc = true) where T : IRedisModelBase { using (var Redis = RedisClientManager.GetClient()) { string tempKey = string.Format("Temp:{0}", Guid.NewGuid().ToString()); Redis.AddRangeToSortedSet(tempKey, ids, 0.0); string intoSetKey = string.Format("OUT:{0}", Guid.NewGuid().ToString()); Redis.StoreIntersectFromSortedSets(intoSetKey, tempKey, RedisKeyFactory.QueryKeyWithProperty <T>(propertyName)); Redis.Remove(tempKey); if (startNum > 0) { startNum--; } else { startNum = 0; } int endNum = -1; if (num == 0) // get all { startNum = 0; } else { endNum = startNum + num - 1; } var sortedIds = isDesc ? Redis.GetRangeFromSortedSetDesc(intoSetKey, startNum, endNum) : Redis.GetRangeFromSortedSet(intoSetKey, startNum, endNum); Redis.Remove(intoSetKey); return(sortedIds); } }
public void DoIndexBySortedSet <T>(string idVal, string propertyName, object value, bool isRemoveIndex = false) where T : IRedisModelBase { string queryKey = RedisKeyFactory.QueryKeyWithProperty <T>(propertyName); using (var Redis = RedisClientManager.GetClient()) { if (isRemoveIndex) { Redis.RemoveItemFromSortedSet(queryKey, idVal); } else { if (value.GetType().Equals(typeof(DateTime))) { Redis.AddItemToSortedSet(queryKey, idVal, ((DateTime)value).Ticks); } else { Redis.AddItemToSortedSet(queryKey, idVal, Convert.ToDouble(value)); } } } }