Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public RedisValue ExecValue(RedisCommand command)
 {
     Enqueue(command);
     ReadResultForCommand(command);
     return command.Value;
 }
Ejemplo n.º 3
0
 public void BufferCommand(RedisCommand command)
 {
     CommandBuffer.Append(command);    
 }
Ejemplo n.º 4
0
 static bool IsSelect(RedisCommand command)
 {
     return (command is SelectCommand) || CommandNameIs(command, Command.Select);    
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 6
0
 static bool IsExec(RedisCommand command)
 {
     return (command is ExecCommand) || CommandNameIs(command, Command.Exec);
 }
Ejemplo n.º 7
0
 protected int ExecuteInt(String key, RedisCommand command)
 {
     var val = ExecValue(key, command);
     return Pipelining ? 0 : (int) val;
 }
Ejemplo n.º 8
0
 internal void ReadResultForCommand(RedisCommand command)
 {
     if (_sendQueue.Contains(command)) 
     {
         if (_sendAllOnRead)
             SendAllCommands();
         else
             SendCommand(command);
     }
     if (_receiveQueue.Contains(command)) 
     {
         BeginReadReplies();
     }
 }
Ejemplo n.º 9
0
 protected RedisValue ExecValue(String key, RedisCommand command)
 {
     var node = GetNodeForTransformedKey(key);
     return ExecValue(node, command);
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 11
0
 protected void Execute(String key, RedisCommand command)
 {
     Execute(GetNodeForTransformedKey(key), command);
 }
Ejemplo n.º 12
0
        protected void ForEachServer(RedisCommand command)
        {
            if (_onNodeStack != null && _onNodeStack.Count > 0)
            {
                Execute(_onNodeStack.Peek(), command);
                return;
            }

            ForEachServer(node => Execute(node, command));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 15
0
 protected int ExecuteInt(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     return Pipelining ? 0 : (int) val;
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 17
0
 protected long ExecuteLong(IRedisNode node, RedisCommand command)
 {
     var val = ExecValue(node, command);
     if (Pipelining)
         return 0;
     return val;
 }
Ejemplo n.º 18
0
 static bool CommandNameIs(RedisCommand command, string name)
 {
     var cmdName = command.Arguments[0].Text;
     return cmdName.Equals(name, StringComparison.OrdinalIgnoreCase);
 }
Ejemplo n.º 19
0
 protected bool ExecuteBool(IRedisNode node, RedisCommand command)
 {
     return ExecuteInt(node, command) > 0;
 }
Ejemplo n.º 20
0
 static bool IsMulti(RedisCommand command)
 {
     return (command is MultiCommand) || CommandNameIs(command, Command.Multi); 
 }
Ejemplo n.º 21
0
 protected bool ExecuteBool(String key, RedisCommand command)
 {
     return ExecuteInt(key, command) > 0;
 }
Ejemplo n.º 22
0
 static bool IsAuth(RedisCommand command)
 {
     return (command is AuthCommand) || CommandNameIs(command, Command.Auth);    
 }
Ejemplo n.º 23
0
        public void EnqueueCommand(IRedisNode node, RedisCommand command)
        {
			RedisCommandQueue q = GetCommandQueue(node);
 			q.Enqueue(command);
            // if (Pipelined || InTransaction)
             _queuedCommandList.Add(command);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Command to set multiple binary safe arguments
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 void BufferOutput(RedisCommand command)
 {
     _commandBuffer.Append(command);
 }
Ejemplo n.º 25
0
 internal void OnCommandWritten(RedisCommand command)
 {
     if (CommandSent != null)
         CommandSent.Invoke(CallbackArg, command);
 }