Example #1
0
        public void RedisField_Equal_Test() {
            RedisField f1 = new RedisField();
            RedisField f2 = new RedisField();
            Assert.IsTrue(f1 == f2);
            Assert.IsTrue(f1.Equals(f2));

            String str = Guid.NewGuid().ToString();
            f1 = str;
            f2 = str;
            Assert.IsTrue(f1 == f2);
            Assert.IsTrue(f1.Equals(f2));

            Object f3 = f1;
            Assert.IsTrue(f3.Equals(f2));
            Assert.IsTrue(f2.Equals(f3));

            f2 = Guid.NewGuid().ToString();
            Assert.IsTrue(f1 != f2);
            Assert.IsTrue(!f1.Equals(f2));

            Assert.IsTrue(!f3.Equals(f2));
            Assert.IsTrue(!f2.Equals(f3));
        }
 public long SortedSetRemoveRangeByScore(RedisField key, double startScore, double stopScore) {
     using (var client = GetRedisClient()) {
         return client.ZRemRangeByScore(key, startScore, stopScore);
     }
 }
 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 Int64 HashSet(RedisField key, RedisField hashField, RedisField value) {
     using (var client = GetRedisClient()) {
         return client.HSet(key, hashField, value);
     }
 }
 public Int64 HashLength(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.HLen(key);
     }
 }
 public Int64 StringIncrement(RedisField key, Int64 value = 1L) {
     using (var client = GetRedisClient()) {
         return client.IncrBy(key, checked((Int32)value));
     }
 }
 public RedisField StringGet(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.Get(key);
     }
 }
 public Boolean KeyExpire(RedisField key, TimeSpan expiry) {
     using (var client = GetRedisClient()) {
         return client.Expire(key, (Int32)expiry.TotalSeconds);
     }
 }
 public Int64 SortedSetLength(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.ZCard(key);
     }
 }
 public RedisField ListRightPop(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.RPop(key);
     }
 }
 public Int64 ListRightPush(RedisField key, RedisField value) {
     using (var client = GetRedisClient()) {
         return client.RPush(key, value);
     }
 }
 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 Boolean HashDelete(RedisField key, RedisField hashField) {
     using (var client = GetRedisClient()) {
         return client.HDel(key, hashField) == 1;
     }
 }
 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 Boolean KeyExists(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.Exists(key) == 1L;
     }
 }
 public Boolean KeyDelete(RedisField key) {
     using (var client = GetRedisClient()) {
         return client.Del(key) == 1L;
     }
 }
 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 Boolean KeyExpire(RedisField key, DateTime expiry) {
     using (var client = GetRedisClient()) {
         return client.ExpireAt(key, expiry.ToUnixTime());
     }
 }
 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 void StringSet(RedisField key, RedisField value) {
     using (var client = GetRedisClient()) {
         client.Set(key, value);
     }
 }
 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 Double StringIncrement(RedisField key, Double value) {
     using (var client = GetRedisClient()) {
         return client.IncrByFloat(key, value);
     }
 }
 public long SortedSetAdd(RedisField key, RedisField value, double score) {
     using (var client = GetRedisClient()) {
         return client.ZAdd(key, score, value);
     }
 }
 public RedisField HashGet(RedisField key, RedisField hashField) {
     using (var client = GetRedisClient()) {
         return client.HGet(key, hashField);
     }
 }
 public bool SortedSetRemove(RedisField key, RedisField member) {
     using (var client = GetRedisClient()) {
         return client.ZRem(key, member) == 1;
     }
 }
 public Int64 HashSet(RedisField key, RedisEntry hash) {
     using (var client = GetRedisClient()) {
         return client.HSet(key, hash.Name, hash.Value);
     }
 }
 public long SortedSetRemoveRangeByRank(RedisField key, Int32 startPosition, Int32 stopPosition) {
     using (var client = GetRedisClient()) {
         return client.ZRemRangeByRank(key, startPosition, stopPosition);
     }
 }