public CacheManDepository(IPEndPoint[] servers) { _cachemanClient = new CachemanClient(servers); _cachemanClient.Connect(); }
public void REPL() { try { if (_client != null) { Console.Write("\n>"); } else { Console.Write("Type 'connect <ipaddress>' to connect to a server\n>"); } string cmd = Console.ReadLine(); string[] components = (new Regex(@"\s+")).Split(cmd); string command = components[0].ToLowerInvariant(); if (command != "quit" && command != "help" && components.Length < 2) { Console.WriteLine("Error: Every command needs atleast a parameter"); return; } if(_client == null && !command.StartsWith("connect")) { Console.WriteLine("Connect to a server first"); return; } if (command == "quit") { Environment.Exit(0); return; } if (command == "stress") { if (components.Length < 3) { Console.WriteLine("Enter number of stress iterations and size of each value to send"); return; } Stress(Convert.ToInt32(components[1]), Convert.ToInt32(components[2])); return; } if (command == "stressgc") { if (components.Length < 3) { Console.WriteLine("Enter number of stress iterations and size of each value to send"); return; } StressGC(Convert.ToInt32(components[1]), Convert.ToInt32(components[2])); return; } if (command == "connect") { if (components.Length < 2) { Console.WriteLine("Enter ip address of server"); return; } if (components.Length == 2) { _client = new CachemanClient(new IPEndPoint(IPAddress.Parse(components[1]), 16180)); _client.Connect(); Console.WriteLine("Connected to " + components[1]); } if (components.Length >2) { IPEndPoint[] endpoints = new IPEndPoint[components.Length -1]; string servers = ""; for(int i=1;i<components.Length;i++ ) { endpoints[i-1] = new IPEndPoint(IPAddress.Parse(components[i]), 16180); servers += endpoints[i - 1].ToString() + " "; } _client = new CachemanClient(endpoints); Console.Write("Connected to " + servers); } return; } if (command == "help") { Console.WriteLine("Commands:\n set key value\n get key\n delete key\n stress iterations size-of-value" + "\n stressgc iterations size-of-value"); return; } string key = components[1]; if (command == "get") { Stopwatch s = Stopwatch.StartNew(); object ret = _client.Get(key); s.Stop(); Console.WriteLine(ret == null ? "Key not found" : (string)ret); Console.WriteLine("Executed in " + s.ElapsedMilliseconds.ToString() + " milliseconds"); } if (command == "delete") { Stopwatch s = Stopwatch.StartNew(); Console.WriteLine(_client.Delete(key) ? "Deleted" : "Not deleted!"); s.Stop(); Console.WriteLine("Executed in " + s.ElapsedMilliseconds.ToString() + " milliseconds"); } if (command == "set") { if (components.Length < 3) { Console.WriteLine("Need 2 parameters for set command"); return; } Stopwatch s = Stopwatch.StartNew(); Console.WriteLine(_client.Set(key, components[2], -1) ? "Set" : "Not set!"); s.Stop(); Console.WriteLine("Executed in " + s.ElapsedMilliseconds.ToString() + " milliseconds"); } } catch (Exception ex) { Console.WriteLine(ex); } }