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); } }
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()); } }
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()); } }
public RedisField[] ListRange(RedisField key, Int32 startingFrom, Int32 endingAt) { using (var client = GetRedisClient()) { return(client.LRange(key, startingFrom, endingAt) .Select(r => (RedisField)r) .ToArray()); } }
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 未返回数值 }
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); } }
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()); } }
public Int64?SortedSetRank(RedisField key, RedisField member) { using (var client = GetRedisClient()) { var value = client.ZRank(key, member); if (value == -1) { return(null); } return(value); } }
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()); } }
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()); } }
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); } }
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); } }
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); } }
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); } }
public Double SortedSetIncrement(RedisField key, RedisField member, Double value) { using (var client = GetRedisClient()) { return(client.ZIncrBy(key, value, member)); } }
public Int64 SortedSetRemoveRangeByScore(RedisField key, Double startScore, Double stopScore) { using (var client = GetRedisClient()) { return(client.ZRemRangeByScore(key, startScore, stopScore)); } }
public Int64 SortedSetRemoveRangeByRank(RedisField key, Int64 startPosition, Int64 stopPosition) { using (var client = GetRedisClient()) { return(client.ZRemRangeByRank(key, (int)startPosition, (int)stopPosition)); } }
public Int64 SortedSetRemove(RedisField key, RedisField member) { using (var client = GetRedisClient()) { return(client.ZRem(key, member)); } }
public Int64 SortedSetAdd(RedisField key, RedisField value, Double score) { using (var client = GetRedisClient()) { return(client.ZAdd(key, score, value)); } }
public Double HashIncrement(RedisField key, RedisField hashField, Double value) { using (var client = GetRedisClient()) { return(client.HIncrbyFloat(key, hashField, value)); } }
public RedisField HashGet(RedisField key, RedisField hashField) { using (var client = GetRedisClient()) { return(client.HGet(key, hashField)); } }
public Int64 HashSet(RedisField key, RedisEntry hash) { using (var client = GetRedisClient()) { return(client.HSet(key, hash.Name, hash.Value)); } }
public Int64 HashSet(RedisField key, RedisField hashField, RedisField value) { using (var client = GetRedisClient()) { return(client.HSet(key, hashField, value)); } }
//SortedSet api public Int64 SortedSetLength(RedisField key) { using (var client = GetRedisClient()) { return(client.ZCard(key)); } }
public Boolean HashDelete(RedisField key, RedisField hashField) { using (var client = GetRedisClient()) { return(client.HDel(key, hashField) == 1); } }
//Key api public Boolean KeyExists(RedisField key) { using (var client = GetRedisClient()) { return(client.Exists(key) == 1L); } }
public Int64 ListRightPush(RedisField key, RedisField value) { using (var client = GetRedisClient()) { return(client.RPush(key, value)); } }
//List api public Int64 ListLength(RedisField key) { using (var client = GetRedisClient()) { return(client.LLen(key)); } }
public Boolean KeyDelete(RedisField key) { using (var client = GetRedisClient()) { return(client.Del(key) == 1L); } }
public RedisField ListRightPop(RedisField key) { using (var client = GetRedisClient()) { return(client.RPop(key)); } }