protected override bool ExecuteAction() { PooledSocket socket = Socket; if (socket == null) { return(false); } socket.SendCommand(string.Format("delete {0}", HashedKey)); return(String.Compare(socket.ReadResponse(), "DELETED", StringComparison.Ordinal) == 0); }
protected override bool ExecuteAction() { foreach (MemcachedNode server in ServerPool.WorkingServers) { using (PooledSocket ps = server.Acquire()) { if (ps != null) { ps.SendCommand("flush_all"); } } } return(true); }
protected override bool ExecuteAction() { PooledSocket socket = Socket; if (socket == null) { return(false); } socket.SendCommand(String.Concat("incr ", HashedKey, " ", 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 result)); }
protected override bool ExecuteAction() { PooledSocket socket = Socket; if (socket == null) { return(false); } socket.SendCommand("get " + HashedKey); GetResponse r = GetHelper.ReadItem(Socket); if (r != null) { result = ServerPool.Transcoder.Deserialize(r.Item); GetHelper.FinishCurrent(Socket); } return(true); }
protected override bool ExecuteAction() { Dictionary <IPEndPoint, Dictionary <string, string> > retval = new Dictionary <IPEndPoint, Dictionary <string, string> >(); foreach (MemcachedNode server in 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; } } results = new ServerStats(retval); return(true); }
protected override bool ExecuteAction() { // {hashed key -> normal key}: will be used when mapping the returned items back to the original keys Dictionary <string, string> hashedToReal = new Dictionary <string, string>(StringComparer.Ordinal); // {normal key -> hashed key}: we have to hash all keys anyway, so we better cache them to improve performance instead of doing the hashing later again Dictionary <string, string> realToHashed = new Dictionary <string, string>(StringComparer.Ordinal); IMemcachedKeyTransformer transformer = ServerPool.KeyTransformer; // and store them with the originals so we can map the returned items // to the original keys foreach (string s in keys) { string hashed = transformer.Transform(s); hashedToReal[hashed] = s; realToHashed[s] = hashed; } // map each key to the appropriate server in the pool IDictionary <MemcachedNode, IList <string> > splitKeys = ServerPool.SplitKeys(keys); // we'll open 1 socket for each server List <PooledSocket> sockets = new List <PooledSocket>(); try { // send a 'gets' to each server foreach (KeyValuePair <MemcachedNode, IList <string> > kp in splitKeys) { // gets <keys> // // keys: key key key key string[] command = new string[kp.Value.Count + 1]; command[0] = "gets"; kp.Value.CopyTo(command, 1); for (int i = 1; i < command.Length; i++) { command[i] = realToHashed[command[i]]; } PooledSocket socket = kp.Key.Acquire(); if (socket == null) { continue; } sockets.Add(socket); socket.SendCommand(String.Join(" ", command)); } Dictionary <string, object> retval = new Dictionary <string, object>(StringComparer.Ordinal); Dictionary <string, ulong> cas = new Dictionary <string, ulong>(StringComparer.Ordinal); // process each response and build a dictionary from the results foreach (PooledSocket socket in sockets) { try { GetResponse r; while ((r = GetHelper.ReadItem(socket)) != null) { string originalKey = hashedToReal[r.Key]; retval[originalKey] = ServerPool.Transcoder.Deserialize(r.Item); cas[originalKey] = r.CasValue; } } catch (NotSupportedException) { throw; } catch (Exception e) { log.Error(e); } } result = retval; casValues = cas; } finally { foreach (PooledSocket socket in sockets) { ((IDisposable)socket).Dispose(); } } return(true); }