예제 #1
0
 public void HashSet(RedisField key, IList <RedisEntry> pairs)
 {
     using (var client = GetRedisClient()) {
         var hashFields = pairs.Select(p => (Byte[])p.Name).ToArray();
         var values     = pairs.Select(p => (Byte[])p.Value).ToArray();
         client.HMSet(key, hashFields, values);
     }
 }
예제 #2
0
 public RedisField[] SortedSetRangeByRank(RedisField key, Int32 startPosition = 0, Int32 stopPosition = -1)
 {
     using (var client = GetRedisClient()) {
         return(client.ZRange(key, startPosition, stopPosition)
                .Select(r => (RedisField)r)
                .ToArray());
     }
 }
예제 #3
0
 public RedisField[] SortedSetRangeByScore(RedisField key, double startScore = double.NegativeInfinity, double stopScore = double.PositiveInfinity, Int32 skip = 0, Int32 take = -1)
 {
     using (var client = GetRedisClient()) {
         return(client.ZRangeByScore(key, startScore, stopScore, skip, take)
                .Select(r => (RedisField)r)
                .ToArray());
     }
 }
예제 #4
0
 public RedisField[] ListRange(RedisField key, Int32 startingFrom, Int32 endingAt)
 {
     using (var client = GetRedisClient()) {
         return(client.LRange(key, startingFrom, endingAt)
                .Select(r => (RedisField)r)
                .ToArray());
     }
 }
예제 #5
0
 public Int64 ListRightPush(RedisField key, IList <RedisField> values)
 {
     using (var client = (IRedisClient)GetRedisClient()) {
         client.AddRangeToList((String)key,
                               values.Select(x => (String)x).ToList());
     }
     return(1); //因 ServiceStack.Redis 未返回数值
 }
예제 #6
0
 public Double?SortedSetScore(RedisField key, RedisField member)
 {
     using (var client = GetRedisClient()) {
         var value = client.ZScore(key, member);
         if (Double.IsNaN(value))
         {
             return(null);
         }
         return(value);
     }
 }
예제 #7
0
 public RedisField[] HashGet(RedisField key, IList <RedisField> hashFields)
 {
     using (var client = GetRedisClient()) {
         var bytes = client.HMGet(key, hashFields.Select(h => (Byte[])h).ToArray());
         if (bytes == null)
         {
             return(null);
         }
         return(bytes.Select(x => (RedisField)x).ToArray());
     }
 }
예제 #8
0
 public Int64?SortedSetRank(RedisField key, RedisField member)
 {
     using (var client = GetRedisClient()) {
         var value = client.ZRank(key, member);
         if (value == -1)
         {
             return(null);
         }
         return(value);
     }
 }
예제 #9
0
 public RedisField[] SortedSetRangeByRank(RedisField key, Int64 startPosition = 0, Int64 stopPosition = -1, Order order = Order.Ascending)
 {
     using (var client = GetRedisClient()) {
         Byte[][] bytes = order == Order.Ascending
             ? client.ZRange(key, (int)startPosition, (int)stopPosition)
             : client.ZRevRange(key, (int)startPosition, (int)stopPosition);
         if (bytes == null)
         {
             return(null);
         }
         return(bytes.Select(r => (RedisField)r)
                .ToArray());
     }
 }
예제 #10
0
 public RedisField[] SortedSetRangeByScore(RedisField key, Double startScore = Double.NegativeInfinity, Double stopScore = Double.PositiveInfinity, Int64 skip = 0, Int64 take = -1, Order order = Order.Ascending)
 {
     using (var client = GetRedisClient()) {
         Byte[][] bytes = order == Order.Ascending
             ? client.ZRangeByScore(key, startScore, stopScore, (int)skip, (int)take)
             : client.ZRevRangeByScore(key, startScore, stopScore, (int)skip, (int)take);
         if (bytes == null)
         {
             return(null);
         }
         return(bytes.Select(r => (RedisField)r)
                .ToArray());
     }
 }
예제 #11
0
 public RedisEntry[] HashGetAll(RedisField key)
 {
     using (var client = GetRedisClient()) {
         var bytes = client.HGetAll(key);
         if (bytes == null)
         {
             return(null);
         }
         var list = new RedisEntry[bytes.Length / 2];
         for (int i = 0; i < list.Length; i++)
         {
             list[i] = new RedisEntry(bytes[2 * i], bytes[2 * i + 1]);
         }
         return(list);
     }
 }
예제 #12
0
 public RedisEntry[] HashGetAll(RedisField key)
 {
     using (var client = GetRedisClient()) {
         var hash = client.HGetAll(key);
         if (hash.Length == 0)
         {
             return(null);
         }
         var list = new RedisEntry[hash.Length / 2];
         for (int i = 0; i < list.Length; i++)
         {
             list[i] = new RedisEntry(hash[2 * i], hash[2 * i + 1]);
         }
         return(list);
     }
 }
예제 #13
0
 public RedisEntry[] SortedSetRangeByScoreWithScores(RedisField key, Double startScore = Double.NegativeInfinity, Double stopScore = Double.PositiveInfinity, Int64 skip = 0, Int64 take = -1, Order order = Order.Ascending)
 {
     using (var client = GetRedisClient()) {
         Byte[][] bytes = order == Order.Ascending
             ? client.ZRangeByScoreWithScores(key, startScore, stopScore, (int)skip, (int)take)
             : client.ZRevRangeByScoreWithScores(key, startScore, stopScore, (int)skip, (int)take);
         if (bytes == null)
         {
             return(null);
         }
         var list = new RedisEntry[bytes.Length / 2];
         for (int i = 0; i < list.Length; i++)
         {
             list[i] = new RedisEntry(bytes[2 * i], bytes[2 * i + 1]);
         }
         return(list);
     }
 }
예제 #14
0
 public RedisEntry[] SortedSetRangeByRankWithScores(RedisField key, Int64 startPosition = 0, Int64 stopPosition = -1, Order order = Order.Ascending)
 {
     using (var client = GetRedisClient()) {
         Byte[][] bytes = order == Order.Ascending
             ? client.ZRangeWithScores(key, (int)startPosition, (int)stopPosition)
             : client.ZRevRangeWithScores(key, (int)startPosition, (int)stopPosition);
         if (bytes == null)
         {
             return(null);
         }
         var list = new RedisEntry[bytes.Length / 2];
         for (int i = 0; i < list.Length; i++)
         {
             list[i] = new RedisEntry(bytes[2 * i], bytes[2 * i + 1]);
         }
         return(list);
     }
 }
예제 #15
0
 public Double SortedSetIncrement(RedisField key, RedisField member, Double value)
 {
     using (var client = GetRedisClient()) {
         return(client.ZIncrBy(key, value, member));
     }
 }
예제 #16
0
 public Int64 SortedSetRemoveRangeByScore(RedisField key, Double startScore, Double stopScore)
 {
     using (var client = GetRedisClient()) {
         return(client.ZRemRangeByScore(key, startScore, stopScore));
     }
 }
예제 #17
0
 public Int64 SortedSetRemoveRangeByRank(RedisField key, Int64 startPosition, Int64 stopPosition)
 {
     using (var client = GetRedisClient()) {
         return(client.ZRemRangeByRank(key, (int)startPosition, (int)stopPosition));
     }
 }
예제 #18
0
 public Int64 SortedSetRemove(RedisField key, RedisField member)
 {
     using (var client = GetRedisClient()) {
         return(client.ZRem(key, member));
     }
 }
예제 #19
0
 public Int64 SortedSetAdd(RedisField key, RedisField value, Double score)
 {
     using (var client = GetRedisClient()) {
         return(client.ZAdd(key, score, value));
     }
 }
예제 #20
0
 public Double HashIncrement(RedisField key, RedisField hashField, Double value)
 {
     using (var client = GetRedisClient()) {
         return(client.HIncrbyFloat(key, hashField, value));
     }
 }
예제 #21
0
 public RedisField HashGet(RedisField key, RedisField hashField)
 {
     using (var client = GetRedisClient()) {
         return(client.HGet(key, hashField));
     }
 }
예제 #22
0
 public Int64 HashSet(RedisField key, RedisEntry hash)
 {
     using (var client = GetRedisClient()) {
         return(client.HSet(key, hash.Name, hash.Value));
     }
 }
예제 #23
0
 public Int64 HashSet(RedisField key, RedisField hashField, RedisField value)
 {
     using (var client = GetRedisClient()) {
         return(client.HSet(key, hashField, value));
     }
 }
예제 #24
0
        //SortedSet api

        public Int64 SortedSetLength(RedisField key)
        {
            using (var client = GetRedisClient()) {
                return(client.ZCard(key));
            }
        }
예제 #25
0
 public Boolean HashDelete(RedisField key, RedisField hashField)
 {
     using (var client = GetRedisClient()) {
         return(client.HDel(key, hashField) == 1);
     }
 }
예제 #26
0
        //Key api

        public Boolean KeyExists(RedisField key)
        {
            using (var client = GetRedisClient()) {
                return(client.Exists(key) == 1L);
            }
        }
예제 #27
0
 public Int64 ListRightPush(RedisField key, RedisField value)
 {
     using (var client = GetRedisClient()) {
         return(client.RPush(key, value));
     }
 }
예제 #28
0
        //List api

        public Int64 ListLength(RedisField key)
        {
            using (var client = GetRedisClient()) {
                return(client.LLen(key));
            }
        }
예제 #29
0
 public Boolean KeyDelete(RedisField key)
 {
     using (var client = GetRedisClient()) {
         return(client.Del(key) == 1L);
     }
 }
예제 #30
0
 public RedisField ListRightPop(RedisField key)
 {
     using (var client = GetRedisClient()) {
         return(client.RPop(key));
     }
 }