Пример #1
0
        /// <summary>
        /// Command to set multiple binary safe arguments
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public void Append(RedisCommand command)
        {
            var elems = command.Arguments;

            AppendLengthMeta((byte)'*', elems.Length);
            
            foreach (var arg in elems)
            {
                WriteBulk(arg.Data);
            }
        }
Пример #2
0
 public RedisValue ExecValue(RedisCommand command)
 {
     Enqueue(command);
     ReadResultForCommand(command);
     return command.Value;
 }
Пример #3
0
 public void BufferCommand(RedisCommand command)
 {
     CommandBuffer.Append(command);    
 }
Пример #4
0
 static bool IsSelect(RedisCommand command)
 {
     return (command is SelectCommand) || CommandNameIs(command, Command.Select);    
 }
Пример #5
0
 static bool CommandNameIs(RedisCommand command, byte[] name)
 {
     var cmdName = command.Arguments[0];
     if (name.IsEqualTo(cmdName)) 
         return true;
     var temp = Encoding.UTF8.GetString(name);
     return CommandNameIs(command, temp);
 }
Пример #6
0
 static bool IsExec(RedisCommand command)
 {
     return (command is ExecCommand) || CommandNameIs(command, Command.Exec);
 }
Пример #7
0
 protected int ExecuteInt(String key, RedisCommand command)
 {
     var val = ExecValue(key, command);
     return Pipelining ? 0 : (int) val;
 }
Пример #8
0
 internal void ReadResultForCommand(RedisCommand command)
 {
     if (_sendQueue.Contains(command)) 
     {
         if (_sendAllOnRead)
             SendAllCommands();
         else
             SendCommand(command);
     }
     if (_receiveQueue.Contains(command)) 
     {
         BeginReadReplies();
     }
 }
Пример #9
0
 protected RedisValue ExecValue(String key, RedisCommand command)
 {
     var node = GetNodeForTransformedKey(key);
     return ExecValue(node, command);
 }
Пример #10
0
        private RedisValue ExecValue(IRedisNode node, RedisCommand command)
        {
            EnqueueCommand(node, command);
            
            if (Pipelining || InTransaction)
                return RedisValue.Empty;

            try
            {
                return command.Value;
            }
            catch (Exception e)
            {
                // TODO generic catch-all does not seem to be a good idea now. Some errors (like command not supported by server) should be exposed 
                // while retaining the fire-and-forget behavior
                HandleException(e);
                throw;
            }
        }
Пример #11
0
 protected void Execute(String key, RedisCommand command)
 {
     Execute(GetNodeForTransformedKey(key), command);
 }
Пример #12
0
        protected void ForEachServer(RedisCommand command)
        {
            if (_onNodeStack != null && _onNodeStack.Count > 0)
            {
                Execute(_onNodeStack.Peek(), command);
                return;
            }

            ForEachServer(node => Execute(node, command));
        }
Пример #13
0
        public static void WriteAsync(this PooledSocket socket, RedisCommand command, Action<RedisCommand> callback)
        {
            var buffer = new CommandBuffer();
            buffer.Append(command);

            var state = new ClientAsyncWriteState
            {
                Buffer = buffer.Data,
                CallbackArg = command,
                WorkSocket = socket.Socket
            };

            if (callback != null)
            {
                state.CommandSent += (args, cmd) => callback(cmd);
            }
            socket.Socket.BeginSend(buffer.Data, 0, buffer.Size, SocketFlags.None,
                new AsyncCallback(EndWriteCmdAsynch), state);
        }
Пример #14
0
		public RedisCommand Enqueue(RedisCommand command)
        {
		    var empty = _sendQueue.Count == 0;
            if (empty)
            {
                var socket = Socket;
                RedisCommand cmd = null;

                if (!socket.IsAuthorized && !String.IsNullOrEmpty(Node.Password) && !IsAuth(command))
                {
                    cmd = new AuthCommand(Node.Password);
                    _sendQueue.Enqueue( cmd );
                }

                // Select proper db if specified in config or (socket.CurrentDB <> currentDB)
                // Read the comments on Select to get some background on the following.
                // Im not sure i like this.
                if (socket.CurrentDb != CurrentDB && !IsSelect(command))
                {
                    cmd = new SelectCommand(CurrentDB);              
                    _sendQueue.Enqueue(cmd);
                }
                if (cmd != null)
                    cmd.Queue = this;
            }
            if (empty && IsTransactional)
            {
                _sendQueue.Enqueue(new MultiCommand());
                _multiCount++;
            }
            if (IsMulti(command))
            {
                if (IsTransactional)
                    throw new RedisClientException("Cannot nest transactions");
                _multiCount++;
            }
            if (IsExec(command))
            {
                //if (_multiCount == 1)
            }
            _sendQueue.Enqueue(command);
		    command.Queue = this;
            return command;
        }
Пример #15
0
 protected int ExecuteInt(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     return Pipelining ? 0 : (int) val;
 }
Пример #16
0
 void SendCommand(RedisCommand command)
 {
     if (_sendQueue.Contains(command)) 
     {
         RedisCommand dequeued;
         do 
         {
             dequeued = _sendQueue.Dequeue();
             BufferOutput(dequeued);
             _receiveQueue.Enqueue(dequeued);
         } while (command != dequeued);
         FlushCommandBuffer();
     }
 }
Пример #17
0
 protected long ExecuteLong(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     if (Pipelining)
         return 0;
     return val;
 }
Пример #18
0
 static bool CommandNameIs(RedisCommand command, string name)
 {
     var cmdName = command.Arguments[0].Text;
     return cmdName.Equals(name, StringComparison.OrdinalIgnoreCase);
 }
Пример #19
0
 protected bool ExecuteBool(IRedisNode node, RedisCommand command)
 {
     return ExecuteInt(node, command) > 0;
 }
Пример #20
0
 static bool IsMulti(RedisCommand command)
 {
     return (command is MultiCommand) || CommandNameIs(command, Command.Multi); 
 }
Пример #21
0
 protected bool ExecuteBool(String key, RedisCommand command)
 {
     return ExecuteInt(key, command) > 0;
 }
Пример #22
0
 static bool IsAuth(RedisCommand command)
 {
     return (command is AuthCommand) || CommandNameIs(command, Command.Auth);    
 }
Пример #23
0
        public void EnqueueCommand(IRedisNode node, RedisCommand command)
        {
			RedisCommandQueue q = GetCommandQueue(node);
 			q.Enqueue(command);
            // if (Pipelined || InTransaction)
             _queuedCommandList.Add(command);
        }
Пример #24
0
 /// <summary>
 /// Command to set multiple binary safe arguments
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 void BufferOutput(RedisCommand command)
 {
     _commandBuffer.Append(command);
 }
Пример #25
0
 internal void OnCommandWritten(RedisCommand command)
 {
     if (CommandSent != null)
         CommandSent.Invoke(CallbackArg, command);
 }