Multi() static private method

static private Multi ( RedisResult inner ) : RedisResult
inner RedisResult
return RedisResult
        private RedisResult ReadSingleResult()
        {
            byte b = ReadByteOrFail();

            switch ((char)b)
            {
            case '+':
                return(RedisResult.Message(ReadBytesToCrlf()));

            case '-':
                return(RedisResult.Error(ReadStringToCrlf()));

            case ':':
                return(RedisResult.Integer(ReadInt64()));

            case '$':
                return(RedisResult.Bytes(ReadBulkBytes()));

            case '*':
                var count = (int)ReadInt64();
                if (count == -1)
                {
                    return(RedisResult.Multi(null));
                }
                var inner = new RedisResult[count];
                for (int i = 0; i < count; i++)
                {
                    inner[i] = ReadSingleResult();
                }
                return(RedisResult.Multi(inner));

            default:
                throw new RedisException("Not expecting header: &x" + b.ToString("x2"));
            }
        }
示例#2
0
        void IMultiMessage.Execute(RedisConnectionBase conn, ref int currentDb)
        {
            var pending = messages;

            if (ExecutePreconditions(conn, ref currentDb))
            {
                conn.WriteRaw(this);                                                         // MULTI
                List <QueuedMessage> newlyQueued = new List <QueuedMessage>(pending.Length); // estimate same length
                for (int i = 0; i < pending.Length; i++)
                {
                    conn.WriteMessage(ref currentDb, pending[i], newlyQueued);
                }
                newlyQueued.TrimExcess();
                conn.WriteMessage(ref currentDb, Execute(newlyQueued), null);
            }
            else
            {
                // preconditions failed; ABORT
                conn.WriteMessage(ref currentDb, RedisMessage.Create(-1, RedisLiteral.UNWATCH).ExpectOk().Critical(), null);

                // even though these weren't written, we still need to mark them cancelled
                exec.Abort(pending);
                // spoof a rollback; same appearance to the caller
                exec.Complete(RedisResult.Multi(null), false);
            }
        }
        void IMultiMessage.Execute(RedisConnectionBase conn, ref int currentDb)
        {
            RedisMessage[] pending       = messages;
            int            estimateCount = pending.Length;

            if (ExecutePreconditions(conn, ref currentDb))
            {
                conn.WriteRaw(this); // MULTI
                var newlyQueued = new List <QueuedMessage>(pending.Length);
                for (int i = 0; i < pending.Length; i++)
                {
                    conn.WriteMessage(ref currentDb, pending[i], newlyQueued);
                }
                newlyQueued.TrimExcess();
                conn.WriteMessage(ref currentDb, Execute(newlyQueued), null);
            }
            else
            {
                // preconditions failed; ABORT
                conn.WriteMessage(ref currentDb, Create(-1, RedisLiteral.UNWATCH).ExpectOk().Critical(), null);
                exec.Complete(RedisResult.Multi(null)); // spoof a rollback; same appearance to the caller
            }
        }