/// <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); } }
public RedisValue ExecValue(RedisCommand command) { Enqueue(command); ReadResultForCommand(command); return command.Value; }
public void BufferCommand(RedisCommand command) { CommandBuffer.Append(command); }
static bool IsSelect(RedisCommand command) { return (command is SelectCommand) || CommandNameIs(command, Command.Select); }
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); }
static bool IsExec(RedisCommand command) { return (command is ExecCommand) || CommandNameIs(command, Command.Exec); }
protected int ExecuteInt(String key, RedisCommand command) { var val = ExecValue(key, command); return Pipelining ? 0 : (int) val; }
internal void ReadResultForCommand(RedisCommand command) { if (_sendQueue.Contains(command)) { if (_sendAllOnRead) SendAllCommands(); else SendCommand(command); } if (_receiveQueue.Contains(command)) { BeginReadReplies(); } }
protected RedisValue ExecValue(String key, RedisCommand command) { var node = GetNodeForTransformedKey(key); return ExecValue(node, command); }
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; } }
protected void Execute(String key, RedisCommand command) { Execute(GetNodeForTransformedKey(key), command); }
protected void ForEachServer(RedisCommand command) { if (_onNodeStack != null && _onNodeStack.Count > 0) { Execute(_onNodeStack.Peek(), command); return; } ForEachServer(node => Execute(node, command)); }
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); }
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; }
protected int ExecuteInt(IRedisNode node, RedisCommand command) { var val = ExecValue(node, command); return Pipelining ? 0 : (int) val; }
void SendCommand(RedisCommand command) { if (_sendQueue.Contains(command)) { RedisCommand dequeued; do { dequeued = _sendQueue.Dequeue(); BufferOutput(dequeued); _receiveQueue.Enqueue(dequeued); } while (command != dequeued); FlushCommandBuffer(); } }
protected long ExecuteLong(IRedisNode node, RedisCommand command) { var val = ExecValue(node, command); if (Pipelining) return 0; return val; }
static bool CommandNameIs(RedisCommand command, string name) { var cmdName = command.Arguments[0].Text; return cmdName.Equals(name, StringComparison.OrdinalIgnoreCase); }
protected bool ExecuteBool(IRedisNode node, RedisCommand command) { return ExecuteInt(node, command) > 0; }
static bool IsMulti(RedisCommand command) { return (command is MultiCommand) || CommandNameIs(command, Command.Multi); }
protected bool ExecuteBool(String key, RedisCommand command) { return ExecuteInt(key, command) > 0; }
static bool IsAuth(RedisCommand command) { return (command is AuthCommand) || CommandNameIs(command, Command.Auth); }
public void EnqueueCommand(IRedisNode node, RedisCommand command) { RedisCommandQueue q = GetCommandQueue(node); q.Enqueue(command); // if (Pipelined || InTransaction) _queuedCommandList.Add(command); }
/// <summary> /// Command to set multiple binary safe arguments /// </summary> /// <param name="command"></param> /// <returns></returns> void BufferOutput(RedisCommand command) { _commandBuffer.Append(command); }
internal void OnCommandWritten(RedisCommand command) { if (CommandSent != null) CommandSent.Invoke(CallbackArg, command); }