예제 #1
0
        public T Load <T>(string partitionKey, string rangeKey) where T : new()
        {
            IRedis redis = (IRedis) new T();

            if (redis.RedisEntityType == RedisEntityType.String)
            {
                return(RedisContext.Get <T>(redis.MakeRedisKey(partitionKey, rangeKey)));
            }
            else
            {
                throw new NotImplementedException("load will not work with lists");
            }
        }
예제 #2
0
        public void InsertSortedSetWithAutoScore <T>(string key, ref IRedis redis)
        {
            if (redis.RedisScore >= 1)
            {
                RemoveFromSortedSet(key, redis.RedisScore, redis.RedisScore);
                InsertSortedSet <T>(key, redis, redis.RedisScore);
                return;
            }
            var maxScore = RedisFirstItemScore();
            var count    = SortedSetCount(key);
            var score    = maxScore - count;

            redis.RedisScore = score;
            InsertSortedSet <T>(key, redis, score);
        }
예제 #3
0
        public IEnumerable <T> Scan <T>(string tableName) where T : new()
        {
            IRedis redis = (IRedis) new T();

            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new Exception("scan method on redis needs tablename");
            }
            if (redis.RedisEntityType != RedisEntityType.String)
            {
                throw new Exception("you can only use this method for RedisEntityType.String models");
            }
            var searchPattern = tableName + ":*";
            var keys          = RedisContext.SearchKeys(searchPattern);

            return(keys.Select(key => RedisContext.Get <T>(key)).ToList());
        }
예제 #4
0
        public IEnumerable <T> Query <T>(string partitionKey, double min, double max) where T : new()
        {
            IRedis redis = (IRedis) new T();

            if (redis.RedisEntityType == RedisEntityType.String)
            {
                var searchPattern = redis.MakeRedisKey(partitionKey);
                if (searchPattern[searchPattern.Length - 1] != '*')
                {
                    searchPattern += "*";
                }
                var keys = RedisContext.SearchKeys(searchPattern);
                return(keys.Select(key => RedisContext.Get <T>(key)).ToList());
            }
            else if (redis.RedisEntityType == RedisEntityType.SortedList)
            {
                var sortedkey = redis.MakeRedisKey(partitionKey).Replace("*", "");
                return(GetSortedSetByRange <T>(sortedkey, min, max));
            }
            return(null);
        }
예제 #5
0
 public bool SortedMemberExists(string key, IRedis redis)
 {
     return(RedisContext.Database.SortedSetRank(key, JsonConvert.SerializeObject(redis)) != null);
 }
예제 #6
0
 public void RemoveFromSortedSet(string key, IRedis redis)
 {
     RedisContext.Database.SortedSetRemove(key, JsonConvert.SerializeObject(redis));
 }
예제 #7
0
 public static long GetSortedSetCount(IRedis redis)
 {
     //Time complexity: O(1)
     return(new DatabaseHelper().SortedSetCount(redis.RedisKey));
 }
예제 #8
0
 private void InsertSortedSet <T>(string key, IRedis redis, double score)
 {
     RedisContext.Database.SortedSetAdd(key, (RedisValue)JsonConvert.SerializeObject(redis), score);
 }
예제 #9
0
 public void InsertSet <T>(string key, IRedis redis) where T : new()
 {
     RedisContext.SetAdd(key: key, item: redis);
 }