protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
            {
                var tran = message as TransactionMessage;

                if (tran != null)
                {
                    var bridge  = connection.Bridge;
                    var wrapped = tran.InnerOperations;
                    switch (result.Type)
                    {
                    case ResultType.SimpleString:
                        if (tran.IsAborted && result.IsEqual(RedisLiterals.BytesOK))
                        {
                            connection.Multiplexer.Trace("Acknowledging UNWATCH (aborted electively)");
                            SetResult(message, false);
                            return(true);
                        }
                        break;

                    case ResultType.MultiBulk:
                        if (!tran.IsAborted)
                        {
                            var arr = result.GetItems();
                            if (arr == null)
                            {
                                connection.Multiplexer.Trace("Server aborted due to failed WATCH");
                                foreach (var op in wrapped)
                                {
                                    op.Wrapped.Cancel();
                                    bridge.CompleteSyncOrAsync(op.Wrapped);
                                }
                                SetResult(message, false);
                                return(true);
                            }
                            else if (wrapped.Length == arr.Length)
                            {
                                connection.Multiplexer.Trace("Server committed; processing nested replies");
                                for (int i = 0; i < arr.Length; i++)
                                {
                                    if (wrapped[i].Wrapped.ComputeResult(connection, arr[i]))
                                    {
                                        bridge.CompleteSyncOrAsync(wrapped[i].Wrapped);
                                    }
                                }
                                SetResult(message, true);
                                return(true);
                            }
                        }
                        break;
                    }
                    // even if we didn't fully understand the result, we still need to do something with
                    // the pending tasks
                    foreach (var op in wrapped)
                    {
                        op.Wrapped.Fail(ConnectionFailureType.ProtocolFailure, null);
                        bridge.CompleteSyncOrAsync(op.Wrapped);
                    }
                }
                return(false);
            }
Ejemplo n.º 2
0
 protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
 {
     if (result.IsEqual(expected))
     {
         SetResult(message, true);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
 public static bool TryGet(RawResult result, out bool value)
 {
     switch (result.Type)
     {
     case ResultType.Integer:
     case ResultType.SimpleString:
     case ResultType.BulkString:
         if (result.IsEqual(one))
         {
             value = true; return(true);
         }
         else if (result.IsEqual(zero))
         {
             value = false; return(true);
         }
         break;
     }
     value = false;
     return(false);
 }
Ejemplo n.º 4
0
            public override bool SetResult(PhysicalConnection connection, Message message, RawResult result)
            {
                var final = base.SetResult(connection, message, result);

                if (result.IsError)
                {
                    if (result.IsEqual(authFail) || result.IsEqual(authRequired))
                    {
                        connection.RecordConnectionFailed(ConnectionFailureType.AuthenticationFailure);
                    }
                    else if (result.AssertStarts(loading))
                    {
                        connection.RecordConnectionFailed(ConnectionFailureType.Loading);
                    }
                    else
                    {
                        connection.RecordConnectionFailed(ConnectionFailureType.ProtocolFailure);
                    }
                }
                return(final);
            }
 protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
 {
     if (result.Type == ResultType.SimpleString && result.IsEqual(QUEUED))
     {
         var q = message as QueuedMessage;
         if (q != null)
         {
             q.WasQueued = true;
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
            protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
            {
                bool happy;

                switch (message.Command)
                {
                case RedisCommand.ECHO:
                    happy = result.Type == ResultType.BulkString && (!establishConnection || result.IsEqual(connection.Multiplexer.UniqueId));
                    break;

                case RedisCommand.PING:
                    happy = result.Type == ResultType.SimpleString && result.IsEqual(RedisLiterals.BytesPONG);
                    break;

                case RedisCommand.TIME:
                    happy = result.Type == ResultType.MultiBulk && result.GetItems().Length == 2;
                    break;

                case RedisCommand.EXISTS:
                    happy = result.Type == ResultType.Integer;
                    break;

                default:
                    happy = true;
                    break;
                }
                if (happy)
                {
                    if (establishConnection)
                    {
                        connection.Bridge.OnFullyEstablished(connection);
                    }
                    SetResult(message, happy);
                    return(true);
                }
                else
                {
                    connection.RecordConnectionFailed(ConnectionFailureType.ProtocolFailure);
                    return(false);
                }
            }
Ejemplo n.º 7
0
            protected override bool SetResultCore(PhysicalConnection connection, Message message, RawResult result)
            {
                if (result.IsNull)
                {
                    SetResult(message, false); // lots of ops return (nil) when they mean "no"
                    return(true);
                }
                switch (result.Type)
                {
                case ResultType.SimpleString:
                    if (result.IsEqual(RedisLiterals.BytesOK))
                    {
                        SetResult(message, true);
                    }
                    else
                    {
                        SetResult(message, result.GetBoolean());
                    }
                    return(true);

                case ResultType.Integer:
                case ResultType.BulkString:
                    SetResult(message, result.GetBoolean());
                    return(true);

                case ResultType.MultiBulk:
                    var items = result.GetItems();
                    if (items.Length == 1)
                    {     // treat an array of 1 like a single reply (for example, SCRIPT EXISTS)
                        SetResult(message, items[0].GetBoolean());
                        return(true);
                    }
                    break;
                }
                return(false);
            }