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