コード例 #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));
     }
 }