Beispiel #1
0
 static String GetPropertyName(RESPObject obj, Int32 index)
 {
     if (!RESPString.IsString(obj.Header))
     {
         throw new RedisClientBindingException("Element at index " + index + " must be an string in order to be a member name");
     }
     return(obj.GetString());
 }
 internal static String GetString(this RESPObject obj)
 {
     if (RESPString.IsString(obj.Header))
     {
         return(obj.ToString());
     }
     else
     {
         throw new RedisClientCastException("Type '" + obj.GetType().Name + "' cannot be cast to 'String'");
     }
 }
Beispiel #3
0
 static void SetQueuedAsDiscarded(RESPObject[] results, String[] commandHeaders, ref Int32 i)
 {
     while (i >= 0 && !commandHeaders[i].Equals("MULTI", StringComparison.Ordinal))
     {
         var element = results[i];
         if (RESPString.IsString(element.Header) && RESPString.Same(element, "QUEUED"))
         {
             results[i] = RESPSimpleString.DISCARDED;
         }
         i--;
     }
 }
        public void AssertOK()
        {
            CheckException();
            if (!RESPString.IsString(_response.Header))
            {
                throw new RedisClientAssertException("Expected result for command was 'OK' but a '" + this.RedisType + "' was received instead");
            }
            var value = _response.GetString();

            if (!"OK".Equals(value, StringComparison.Ordinal))
            {
                throw new RedisClientAssertException("Expected result for command was 'OK' but result was '" + (value ?? "<null>") + "'");
            }
        }
 internal static Double AsDouble(this RESPObject obj)
 {
     if (RESPString.IsString(obj.Header))
     {
         var val = obj.ToString();
         return(String.IsNullOrWhiteSpace(val) ? 0 : Double.Parse(val, RESPObject.FormatInfo));
     }
     else if (obj.Header == RESPHeaders.Integer)
     {
         return(((RESPInteger)obj).Value);
     }
     else
     {
         throw new RedisClientCastException("Type '" + obj.GetType().Name + "' cannot be formatted as 'Double'");
     }
 }
Beispiel #6
0
        static void ZipQueuedAndResults(RESPObject[] results, ref Int32 index)
        {
            Contract.Assert(results.Any(), "Passing empty results to zip.");

            var result = results[index];

            if (result.Header == RESPHeaders.BulkString && RESPString.Same(result, null))
            {
                // EXEC failed due WATCH
                results[index] = RESPError.EXECWATCHFAILED;
            }
            else
            {
                index = ZipUpResults(results, index, result);
            }
        }
Beispiel #7
0
        static int ZipUpResults(RESPObject[] results, Int32 index, RESPObject result)
        {
            var array = result.Cast <RESPArray>();

            results[index] = RESPSimpleString.OK;
            index--;
            var arrayIndex = array.Count - 1;

            while (index >= 0 && arrayIndex >= 0)
            {
                var element = results[index];
                if (RESPString.IsString(element.Header) && RESPString.Same(element, "QUEUED"))
                {
                    results[index] = array[arrayIndex];
                    arrayIndex--;
                }

                index--;
            }
            return(index);
        }
Beispiel #8
0
        internal static Boolean Same(RESPString item, String comparand)
        {
            Contract.Assert(item != null, "Item is null");

            return(String.Equals(item.Value, comparand, StringComparison.OrdinalIgnoreCase));
        }