//Private common store method. private string store(string command, string key, bool keyIsChecked, object value, uint hash, int expiry, ulong unique) { key = key + MemcachedKey; if (!keyIsChecked) { checkKey(key); } var result = serverPool.Execute <string>(hash, "", delegate(PooledSocket socket) { SerializedType type; byte[] bytes; //Serialize object efficiently, store the datatype marker in the flags property. try { bytes = Serializer.Serialize(value, out type, CompressionThreshold); } catch (Exception e) { //If serialization fails, return false; logger.Error("Error serializing object for key '" + key + "'.", e); return(""); } //Create commandline string commandline = ""; switch (command) { case "set": case "add": case "replace": commandline = command + " " + keyPrefix + key + " " + (ushort)type + " " + expiry + " " + bytes.Length + "\r\n"; break; case "append": case "prepend": commandline = command + " " + keyPrefix + key + " 0 0 " + bytes.Length + "\r\n"; break; case "cas": commandline = command + " " + keyPrefix + key + " " + (ushort)type + " " + expiry + " " + bytes.Length + " " + unique + "\r\n"; break; } //Write commandline and serialized object. socket.Write(commandline); socket.Write(bytes); socket.Write("\r\n"); return(socket.ReadResponse()); }); return(result); }
/// <summary> /// This method retrives the status from the serverpool. It checks the connection to all servers /// and returns usage statistics for each server. /// </summary> public Dictionary <string, Dictionary <string, string> > Status() { Dictionary <string, Dictionary <string, string> > results = new Dictionary <string, Dictionary <string, string> >(); foreach (SocketPool pool in serverPool.HostList) { Dictionary <string, string> result = new Dictionary <string, string>(); if (serverPool.Execute <bool>(pool, false, delegate { return(true); })) { result.Add("Status", "Ok"); } else { result.Add("Status", "Dead, next retry at: " + pool.DeadEndPointRetryTime); } result.Add("Sockets in pool", pool.Poolsize.ToString()); result.Add("Acquired sockets", pool.Acquired.ToString()); result.Add("Sockets reused", pool.ReusedSockets.ToString()); result.Add("New sockets created", pool.NewSockets.ToString()); result.Add("New sockets failed", pool.FailedNewSockets.ToString()); result.Add("Sockets died in pool", pool.DeadSocketsInPool.ToString()); result.Add("Sockets died on return", pool.DeadSocketsOnReturn.ToString()); result.Add("Dirty sockets on return", pool.DirtySocketsOnReturn.ToString()); results.Add(pool.Host, result); } return(results); }