public static void FinishCurrent(PooledSocket socket) { string response = socket.ReadResponse(); if (String.Compare(response, "END", StringComparison.Ordinal) != 0) throw new MemcachedClientException("No END was received."); }
public static void FinishCurrent(PooledSocket socket) { string response = socket.ReadResponse(); if (String.Compare(response, "END", StringComparison.Ordinal) != 0) { throw new MemcachedClientException("No END was received."); } }
public static GetResponse ReadItem(PooledSocket socket) { string description = socket.ReadResponse(); if (String.Compare(description, "END", StringComparison.Ordinal) == 0) { return(null); } if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0) { throw new MemcachedClientException("No VALUE response received.\r\n" + description); } ulong cas = 0; string[] parts = description.Split(' '); // response is: // VALUE <key> <flags> <bytes> [<cas unique>] // 0 1 2 3 4 // // cas only exists in 1.2.4+ // if (parts.Length == 5) { if (!UInt64.TryParse(parts[4], out cas)) { throw new MemcachedClientException("Invalid CAS VALUE received."); } } else if (parts.Length < 4) { throw new MemcachedClientException("Invalid VALUE response received: " + description); } ushort flags = UInt16.Parse(parts[2], CultureInfo.InvariantCulture); int length = Int32.Parse(parts[3], CultureInfo.InvariantCulture); byte[] allData = new byte[length]; byte[] eod = new byte[2]; socket.Read(allData, 0, length); socket.Read(eod, 0, 2); // data is terminated by \r\n GetResponse retval = new GetResponse(parts[1], flags, cas, allData); if (log.IsDebugEnabled) { log.DebugFormat("Received value. Data type: {0}, size: {1}.", retval.Item.Flag, retval.Item.Data.Count); } return(retval); }
protected override bool ExecuteAction() { PooledSocket socket = this.Socket; if (socket == null) { return(false); } socket.SendCommand("delete " + this.HashedKey); return(String.Compare(socket.ReadResponse(), "DELETED", StringComparison.Ordinal) == 0); }
public static GetResponse ReadItem(PooledSocket socket) { string description = socket.ReadResponse(); if (String.Compare(description, "END", StringComparison.Ordinal) == 0) return null; if (description.Length < 6 || String.Compare(description, 0, "VALUE ", 0, 6, StringComparison.Ordinal) != 0) throw new MemcachedClientException("No VALUE response received.\r\n" + description); ulong cas = 0; string[] parts = description.Split(' '); // response is: // VALUE <key> <flags> <bytes> [<cas unique>] // 0 1 2 3 4 // // cas only exists in 1.2.4+ // if (parts.Length == 5) { if (!UInt64.TryParse(parts[4], out cas)) throw new MemcachedClientException("Invalid CAS VALUE received."); } else if (parts.Length < 4) { throw new MemcachedClientException("Invalid VALUE response received: " + description); } ushort flags = UInt16.Parse(parts[2], CultureInfo.InvariantCulture); int length = Int32.Parse(parts[3], CultureInfo.InvariantCulture); byte[] allData = new byte[length]; byte[] eod = new byte[2]; socket.Read(allData, 0, length); socket.Read(eod, 0, 2); // data is terminated by \r\n GetResponse retval = new GetResponse(parts[1], flags, cas, allData); if (log.IsDebugEnabled) log.DebugFormat("Received value. Data type: {0}, size: {1}.", retval.Item.Flag, retval.Item.Data.Count); return retval; }
protected override bool ExecuteAction() { PooledSocket socket = this.Socket; if (socket == null) { return(false); } socket.SendCommand(String.Concat("incr ", this.HashedKey, " ", this.amount.ToString(CultureInfo.InvariantCulture))); string response = socket.ReadResponse(); //maybe we should throw an exception when the item is not found? if (String.Compare(response, "NOT_FOUND", StringComparison.Ordinal) == 0) { return(false); } return(UInt32.TryParse(response, out this.result)); }
protected override bool ExecuteAction() { Dictionary <IPEndPoint, Dictionary <string, string> > retval = new Dictionary <IPEndPoint, Dictionary <string, string> >(); foreach (MemcachedNode server in this.ServerPool.WorkingServers) { using (PooledSocket ps = server.Acquire()) { if (ps == null) { continue; } ps.SendCommand("stats"); Dictionary <string, string> serverData = new Dictionary <string, string>(StringComparer.Ordinal); while (true) { string line = ps.ReadResponse(); // stat values are terminated by END if (String.Compare(line, "END", StringComparison.Ordinal) == 0) { break; } // expected response is STAT item_name item_value if (line.Length < 6 || String.Compare(line, 0, "STAT ", 0, 5, StringComparison.Ordinal) != 0) { if (log.IsWarnEnabled) { log.Warn("Unknow response: " + line); } continue; } // get the key&value string[] parts = line.Remove(0, 5).Split(' '); if (parts.Length != 2) { if (log.IsWarnEnabled) { log.Warn("Unknow response: " + line); } continue; } // store the stat item serverData[parts[0]] = parts[1]; } retval[server.EndPoint] = serverData; } } this.results = new ServerStats(retval); return(true); }