예제 #1
0
        protected Message(int db, CommandFlags flags, RedisCommand command)
        {
            bool dbNeeded = RequiresDatabase(command);

            if (db < 0)
            {
                if (dbNeeded)
                {
                    throw ExceptionFactory.DatabaseRequired(false, command);
                }
            }
            else
            {
                if (!dbNeeded)
                {
                    throw ExceptionFactory.DatabaseNotRequired(false, command);
                }
            }

            bool masterOnly = IsMasterOnly(command);

            Db           = db;
            this.command = command;
            this.flags   = flags & UserSelectableFlags;
            if (masterOnly)
            {
                SetMasterOnly();
            }

            createdDateTime  = DateTime.UtcNow;
            createdTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();
        }
        protected Message(int db, CommandFlags flags, RedisCommand command)
        {
            bool dbNeeded = Message.RequiresDatabase(command);

            if (db < 0)
            {
                if (dbNeeded)
                {
                    throw ExceptionFactory.DatabaseRequired(false, command);
                }
            }
            else
            {
                if (!dbNeeded)
                {
                    throw ExceptionFactory.DatabaseNotRequired(false, command);
                }
            }

            if (IsMasterOnly(command))
            {
                switch (GetMasterSlaveFlags(flags))
                {
                case CommandFlags.DemandSlave:
                    throw ExceptionFactory.MasterOnly(false, command, null, null);

                case CommandFlags.DemandMaster:
                    // already fine as-is
                    break;

                case CommandFlags.PreferMaster:
                case CommandFlags.PreferSlave:
                default:     // we will run this on the master, then
                    flags = SetMasterSlaveFlags(flags, CommandFlags.DemandMaster);
                    break;
                }
            }
            this.Db      = db;
            this.command = command;
            this.flags   = flags & UserSelectableFlags;

            createdDateTime  = DateTime.UtcNow;
            createdTimestamp = System.Diagnostics.Stopwatch.GetTimestamp();
        }