예제 #1
0
        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())
            {
                IDictionary <string, double> appIds =
                    Redis.GetRangeWithScoresFromSortedSetByLowestScore(RedisKeyFactory.QueryKeyWithProperty <T>(propertyName), start.GetValueOrDefault().Ticks, end.GetValueOrDefault().Ticks);

                return(appIds.Keys.ToList());
            }
        }
예제 #2
0
        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));
                    }
                }
            }
        }
예제 #3
0
        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));
                    }
                }
            }
        }