private bool Store(ushort flag, ArraySegment <byte> data) { StringBuilder sb = new StringBuilder(100); switch (this.mode) { case StoreCommand.Add: sb.Append("add "); break; case StoreCommand.Replace: sb.Append("replace "); break; case StoreCommand.Set: sb.Append("set "); break; case StoreCommand.Append: sb.Append("append "); break; case StoreCommand.Prepend: sb.Append("prepend "); break; case StoreCommand.CheckAndSet: sb.Append("cas "); break; default: throw new MemcachedClientException(mode + " is not supported."); } sb.Append(this.HashedKey); sb.Append(" "); sb.Append(flag.ToString(CultureInfo.InvariantCulture)); sb.Append(" "); sb.Append(this.expires.ToString(CultureInfo.InvariantCulture)); sb.Append(" "); sb.Append(Convert.ToString(data.Count - data.Offset, CultureInfo.InvariantCulture)); if (mode == StoreCommand.CheckAndSet) { sb.Append(" "); sb.Append(Convert.ToString(this.casValue, CultureInfo.InvariantCulture)); } ArraySegment <byte> commandBuffer = PooledSocket.GetCommandBuffer(sb.ToString()); this.Socket.Write(new ArraySegment <byte>[] { commandBuffer, data, StoreOperation.DataTerminator }); return(String.Compare(this.Socket.ReadResponse(), "STORED", StringComparison.Ordinal) == 0); }
/// <summary> /// Sends the command to the server. The trailing \r\n is automatically appended. /// </summary> /// <param name="value">The command to be sent to the server.</param> public void SendCommand(string value) { this.CheckDisposed(); //this.CheckThread(); if (log.IsDebugEnabled) { log.Debug("SendCommand: " + value); } // send the whole command with only one Write // since Nagle is disabled on the socket this is more efficient than // Write(command), Write("\r\n") this.Write(PooledSocket.GetCommandBuffer(value)); }