public override void Execute(MemcachedSocket memcachedSocket)
		{
			BeforeFlush(memcachedSocket);
			memcachedSocket.Flush();
			AfterFlush(memcachedSocket);

		}
Beispiel #2
0
		public void AfterFlush(MemcachedSocket memcachedSocket)
		{
			string line = memcachedSocket.ReadLine();
			if (line == "END") return;

			CheckResponseStart(line, "VALUE");

			string[] splitLine = line.Split(' ');
			StoredObjectType objType = (StoredObjectType)int.Parse(splitLine[2]);
			int length = int.Parse(splitLine[3]);

			switch (objType)
			{
				case StoredObjectType.IntCounter:
					RetrievedObject = int.Parse(memcachedSocket.ReadLine().Substring(0, length));
					break;
				case StoredObjectType.UIntCounter:
					RetrievedObject = uint.Parse(memcachedSocket.ReadLine().Substring(0, length));
					break;
				case StoredObjectType.LongCounter:
					RetrievedObject = long.Parse(memcachedSocket.ReadLine().Substring(0, length));
					break;
				case StoredObjectType.SerializableObject:
					byte[] bytes = memcachedSocket.ReadBytes(length);
					using (MemoryStream memoryStream = new MemoryStream(bytes))
					{
						RetrievedObject = new BinaryFormatter().Deserialize(memoryStream);
					}
					CheckResponse(memcachedSocket.ReadLine(), "");
					break;
				default:
					throw new Exception("Unexpected StoredObjectType: " + objType.ToString());
			}
			CheckResponse(memcachedSocket.ReadLine(), "END");
		}
Beispiel #3
0
		public override void Execute(MemcachedSocket memcachedSocket)
		{
			memcachedSocket.WriteLine("flush_all");
			memcachedSocket.Flush();

			CheckResponse(memcachedSocket.ReadLine(), "OK");
		}
Beispiel #4
0
		public override void Execute(MemcachedSocket memcachedSocket)
		{
			string response = SendCommandAndReadResponse(memcachedSocket, "add", "STORED", "NOT_STORED", "EXISTS");
			if (response == "EXISTS" || response == "NOT_STORED")
			{
				SendCommandAndReadResponse(memcachedSocket, "replace", "STORED", "NOT_STORED");
			}
		}
		protected string SendCommandAndReadResponse(MemcachedSocket memcachedSocket, string command, params string[] expectedResponses)
		{
			WriteCommandToStream(memcachedSocket, command);
			memcachedSocket.Flush();
			string response = ReadResponseFromStream(memcachedSocket);
			CheckResponse(response, expectedResponses);
			return response;
		}
Beispiel #6
0
		public void AfterFlush(MemcachedSocket memcachedSocket)
		{
			string response = memcachedSocket.ReadLine();
			if (response == "NOT_FOUND") { return; }
			uint result;
			if (uint.TryParse(response, out result))
			{
				RetrievedValue = result;
			}
			else
			{
				throw new UnexpectedResponseMatchException(response, "NOT_FOUND", "<uint value>");
			}
		}
Beispiel #7
0
		public override void Execute(MemcachedSocket memcachedSocket)
		{
			memcachedSocket.WriteLine("stats");
			string line = memcachedSocket.ReadLine();
			while (line.StartsWith("STAT"))
			{
				int indexOfStatName = line.IndexOf(" ") + 1;
				int indexOfStatValue = line.IndexOf(" ", indexOfStatName);
				string name = line.Substring(indexOfStatName, indexOfStatValue - indexOfStatName);
				string value = line.Substring(indexOfStatValue, line.Length - indexOfStatValue);
				Stats.Add(new KeyValuePair<string, string>(name, value));
				line = memcachedSocket.ReadLine();
			}
			CheckResponse(line, "END");
		}
Beispiel #8
0
		public void BeforeFlush(MemcachedSocket memcachedSocket)
		{
			string command;
			uint absAmount;
			if (amount >= 0)
			{
				command = "incr";
				absAmount = (uint)amount;
			}
			else
			{
				command = "decr";
				absAmount = (uint)-amount;
			}
			memcachedSocket.WriteLine(String.Format("{0} {1} {2}", command, this.Key.Hash, absAmount));
		}
		internal void WriteCommandToStream(MemcachedSocket memcachedSocket, string command)
		{
			string firstLine = String.Format("{0} {1} {2} {3} {4}", command, this.Key.Hash, (int)this.objType, Convert.ToString(GetExpiration(expiry), CultureInfo.InvariantCulture), this.dataToBeStored.Length);
			memcachedSocket.WriteLine(firstLine);
			memcachedSocket.WriteLine(dataToBeStored);
		}
		internal string ReadResponseFromStream(MemcachedSocket memcachedSocket)
		{
			return memcachedSocket.ReadLine();
		}
Beispiel #11
0
		public void BeforeFlush(MemcachedSocket memcachedSocket)
		{
			memcachedSocket.WriteLine("set " + this.Key.Hash + " 0 0 0");
			memcachedSocket.WriteLine("");
			memcachedSocket.WriteLine("delete " + this.Key.Hash + " 1");
		}
Beispiel #12
0
		public void AfterFlush(MemcachedSocket memcachedSocket)
		{
			string response = this.ReadResponseFromStream(memcachedSocket);
			CheckResponse(response, Response0, Response1, Response2);
		}
Beispiel #13
0
		public void BeforeFlush(MemcachedSocket memcachedSocket)
		{
			this.WriteCommandToStream(memcachedSocket, Set.Command);
		}
Beispiel #14
0
		public override void Execute(MemcachedSocket memcachedSocket)
		{
			string response = SendCommandAndReadResponse(memcachedSocket, Command, Response0, Response1, Response2);
		}
Beispiel #15
0
		public void AfterFlush(MemcachedSocket memcachedSocket)
		{
			CheckResponse(memcachedSocket.ReadLine(), "STORED");
			CheckResponse(memcachedSocket.ReadLine(), "DELETED");
		}
Beispiel #16
0
		public abstract void Execute(MemcachedSocket memcachedSocket);
Beispiel #17
0
		public void BeforeFlush(MemcachedSocket memcachedSocket)
		{
			memcachedSocket.WriteLine("get " + this.Key.Hash);
		}