Exemplo n.º 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");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public bool SortedMemberExists(string key, IRedis redis)
 {
     return(RedisContext.Database.SortedSetRank(key, JsonConvert.SerializeObject(redis)) != null);
 }
Exemplo n.º 6
0
 public void RemoveFromSortedSet(string key, IRedis redis)
 {
     RedisContext.Database.SortedSetRemove(key, JsonConvert.SerializeObject(redis));
 }
Exemplo n.º 7
0
 public static long GetSortedSetCount(IRedis redis)
 {
     //Time complexity: O(1)
     return(new DatabaseHelper().SortedSetCount(redis.RedisKey));
 }
Exemplo n.º 8
0
 private void InsertSortedSet <T>(string key, IRedis redis, double score)
 {
     RedisContext.Database.SortedSetAdd(key, (RedisValue)JsonConvert.SerializeObject(redis), score);
 }
Exemplo n.º 9
0
 public void InsertSet <T>(string key, IRedis redis) where T : new()
 {
     RedisContext.SetAdd(key: key, item: redis);
 }