private void Button_Click(object sender, RoutedEventArgs e) { // Establish connection the server try { AerospikeClient client = new AerospikeClient("45.55.231.46", 3000); // Create key Aerospike.Client.Key key = new Aerospike.Client.Key("test", "myset", "mykey"); // Create Bins Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); // Write record client.Put(null, key, bin1, bin2); // Read record Record record = client.Get(null, key); Record userRecord = client.Get(null, key); Console.WriteLine("Info:"); Console.WriteLine("Name: " + userRecord.GetValue("name")); Console.WriteLine("Age: " + userRecord.GetValue("age")); // Close connection client.Close(); } catch (AerospikeException.Connection conError) { Console.Write(conError); } }
public override void RunExample(Arguments a) { this.args = (BenchmarkArguments)a; shared = new BenchmarkShared(args); if (args.sync) { ClientPolicy policy = new ClientPolicy(); policy.user = args.user; policy.password = args.password; policy.failIfNotConnected = true; client = new AerospikeClient(policy, args.host, args.port); try { args.SetServerSpecific(client); threads = new BenchmarkThreadSync[args.threadMax]; for (int i = 0; i < args.threadMax; i++) { threads[i] = new BenchmarkThreadSync(console, args, shared, this, client); } RunThreads(); } finally { client.Close(); } } else { console.Info("Maximum concurrent commands: " + args.commandMax); AsyncClientPolicy policy = new AsyncClientPolicy(); policy.user = args.user; policy.password = args.password; policy.failIfNotConnected = true; policy.asyncMaxCommands = args.commandMax; AsyncClient client = new AsyncClient(policy, args.host, args.port); this.client = client; try { args.SetServerSpecific(client); threads = new BenchmarkThreadAsync[args.threadMax]; for (int i = 0; i < args.threadMax; i++) { threads[i] = new BenchmarkThreadAsync(console, args, shared, this, client); } RunThreads(); } finally { client.Close(); } } }
public override void RunExample(Arguments args) { ClientPolicy policy = new ClientPolicy(); policy.user = args.user; policy.password = args.password; policy.failIfNotConnected = true; AerospikeClient client = new AerospikeClient(policy, args.host, args.port); try { args.SetServerSpecific(client); RunExample(client, args); } finally { client.Close(); } }
private void Login() { string server = hostBox.Text.Trim(); int port = int.Parse(portBox.Text.Trim()); string userName = userBox.Text.Trim(); string password = passwordBox.Text.Trim(); ClientPolicy policy = new ClientPolicy(); policy.user = userName; policy.password = password; policy.failIfNotConnected = true; policy.timeout = 600000; AerospikeClient client = new AerospikeClient(policy, server, port); try { if (userName.Equals("admin") && password.Equals("admin")) { Form form = new PasswordForm(client, userName); form.ShowDialog(); } // Query own user. User user = client.QueryUser(null, userName); if (user != null) { bool admin = user.roles.Contains("user-admin"); // Initialize Global Data Globals.RefreshRoles(client, user, admin); Form form = new AdminForm(client, user, admin); form.Show(); } else { throw new Exception("Failed to find user: " + userName); } } catch (Exception) { client.Close(); throw; } }
public static void Main(string[] args) { AerospikeClient client = null; try { Console.WriteLine ("Connecting to Aerospike cluster..."); Stopwatch stopwatch = new Stopwatch (); //Thread[] array = new Thread[accountTotal]; // Establish connection client = new AerospikeClient (asServerIP, asServerPort); // Check to see if the cluster connection succeeded if (client.Connected) { Console.WriteLine ("Connection succeeded!\n"); int feature = 0; while (feature != 99) { // Present options Console.WriteLine ("\n\nWhat would you like to do:"); Console.WriteLine ("1> Generate sequence data for last " + days + " days"); Console.WriteLine ("2> Reconsile sequence data"); Console.WriteLine ("3> Generate Position using CDT and LDT"); Console.WriteLine ("4> List CDT vs LDT - whole list"); Console.WriteLine ("5> List CDT vs LDT - one element"); Console.WriteLine ("99> Exit"); Console.Write ("\nSelect 1-5, 99 and hit enter:"); string input = Console.ReadLine (); if (input.Trim().Length == 0) feature = 99; else feature = int.Parse (input); if (feature != 99) { switch (feature) { case 1: Console.WriteLine ("Generating data..."); DateTime today = DateTime.Now; today = today.Date; // write yesterday to Aerospike DateTime yesterday = today.AddDays (-1); generateTimeSeries (yesterday.ToShortDateString (), client); // write yesterday to file generateTimeSeries (yesterday.ToShortDateString (), null); // write n days for (int dif = 2; dif < days; dif++) { DateTime dayBefore = today.AddDays (-dif); Console.WriteLine ("Writing: " + dayBefore.ToShortDateString ()); generateTimeSeries (dayBefore.ToShortDateString (), client); } Console.WriteLine ("Generating data completed"); break; case 2: Console.WriteLine ("Reconsiling yesterday's data"); #region setup // use admin tools to do this in production RegisterTask rTask = client.Register(null, udfDir + "utility.lua", "utility.lua", Language.LUA); while(!rTask.QueryIfDone()){ Thread.Sleep(20); } // client.CreateIndex(null, ns, seqSet, // "day-seq-index", dayBinName, IndexType.STRING); #endregion today = DateTime.Now; today = today.Date; yesterday = today.AddDays (-1); string yesterdayString = yesterday.ToShortDateString (); // purge first sequence PurgeDay (yesterdayString, client); /// reconciliation from file ReconcileDay (yesterdayString, client); Console.WriteLine ("Reconciliation complete"); break; case 3: Console.WriteLine ("Generating position data using CDT and LDT..."); generateCustomerProduct (client); Console.WriteLine ("Generating data completed"); break; case 4: Console.WriteLine ("CDT vs LDT - Whole list..."); long cdtTotal = 0, ldtTotal = 0, cdtProdCount = 0, ldtProdCount = 0; for (int acc = 0; acc < accountTotal; acc++) { string accString = (acc + 1).ToString (); Key cdtkey = new Key (ns, cdtSet, accString); Key ldtkey = new Key (ns, ldtSet, accString); Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName); LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName); stopwatch.Start (); IList cresult = clist.Scan (); stopwatch.Stop (); if (cresult != null) cdtProdCount += cresult.Count; cdtTotal += stopwatch.ElapsedMilliseconds; stopwatch.Reset (); stopwatch.Start (); IList lresult = llist.Scan (); stopwatch.Stop (); if (lresult != null) ldtProdCount += lresult.Count; ldtTotal += stopwatch.ElapsedMilliseconds; } Console.WriteLine ("CDT avg latency: {0:F5} ms", (double)cdtTotal / cdtProdCount); Console.WriteLine ("LDT avg latency: {0:F5} ms", (double)ldtTotal / ldtProdCount); break; case 5: const int attempts = 50000; Console.WriteLine ("CDT vs LDT - one element..., {0} customers, each product for a customer", attempts); cdtTotal = 0; ldtTotal = 0; long prodCount = 0; Random accRand = new Random (12121); for (int i = 0; i < 50000; i++) { string accString = accRand.Next (1, accountTotal).ToString (); Key cdtkey = new Key (ns, cdtSet, accString); Key ldtkey = new Key (ns, ldtSet, accString); Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName); LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName); IList prods = llist.Scan (); if (prods != null) { prodCount += prods.Count; foreach (IDictionary product in prods) { //Dictionary<string, Object> keyMap = makeKeyMap (product); // CDT stopwatch.Start (); clist.Find (Value.Get (product)); stopwatch.Stop (); cdtTotal += stopwatch.ElapsedMilliseconds; stopwatch.Reset (); // LDT stopwatch.Start (); llist.Find (Value.Get (product)); stopwatch.Stop (); ldtTotal += stopwatch.ElapsedMilliseconds; } } } Console.WriteLine ("CDT avg latency: {0:F5} ms", (double)cdtTotal / prodCount); Console.WriteLine ("LDT avg latency: {0:F5} ms", (double)ldtTotal / prodCount); break; default: break; } } } } } catch (AerospikeException e) { Console.WriteLine ("AerospikeException - Message: " + e.Message); Console.WriteLine ("AerospikeException - StackTrace: " + e.StackTrace); } catch (Exception e) { Console.WriteLine ("Exception - Message: " + e.Message); Console.WriteLine ("Exception - StackTrace: " + e.StackTrace); } finally { if (client != null && client.Connected) { // Close Aerospike server connection client.Close (); } } }
private void ConnectSync() { ClientPolicy policy = new ClientPolicy(); policy.failIfNotConnected = true; if (!user.Equals("")) { policy.user = user; policy.password = password; } client = new AerospikeClient(policy, host, port); try { SetServerSpecific(); } catch (Exception e) { client.Close(); client = null; throw e; } }
static void Main(string[] args) { Console.WriteLine("***** Welcome to Aerospike Developer Training *****\n"); AerospikeClient client = null; try { Console.WriteLine("INFO: Connecting to Aerospike cluster..."); // Connecting to Aerospike cluster // Specify IP of one of the nodes in the cluster string asServerIP = "172.16.159.198"; // Specity Port that the node is listening on int asServerPort = 3000; // Establish connection client = new AerospikeClient(asServerIP, asServerPort); // Check to see if the cluster connection succeeded if (client.Connected) { Console.WriteLine("INFO: Connection to Aerospike cluster succeeded!\n"); // Create instance of UserService UserService us = new UserService(client); // Create instance of TweetService TweetService ts = new TweetService(client); // Present options Console.WriteLine("What would you like to do:"); Console.WriteLine("1> Create A User And A Tweet"); Console.WriteLine("2> Read A User Record"); Console.WriteLine("3> Batch Read Tweets For A User"); Console.WriteLine("4> Scan All Tweets For All Users"); Console.WriteLine("5> Record UDF -- Update User Password"); Console.WriteLine("6> Query Tweets By Username And Users By Tweet Count Range"); Console.WriteLine("7> Stream UDF -- Aggregation Based on Tweet Count By Region"); Console.WriteLine("0> Exit"); Console.Write("\nSelect 0-7 and hit enter:"); byte feature = byte.Parse(Console.ReadLine()); if (feature != 0) { switch (feature) { case 1: Console.WriteLine("\n********** Your Selection: Create User And A Tweet **********\n"); us.createUser(); ts.createTweet(); break; case 2: Console.WriteLine("\n********** Your Selection: Read A User Record **********\n"); us.getUser(); break; case 3: Console.WriteLine("\n********** Your Selection: Batch Read Tweets For A User **********\n"); us.batchGetUserTweets(); break; case 4: Console.WriteLine("\n********** Your Selection: Scan All Tweets For All Users **********\n"); ts.scanAllTweetsForAllUsers(); break; case 5: Console.WriteLine("\n********** Your Selection: Record UDF -- Update User Password **********\n"); us.updatePasswordUsingUDF(); break; case 6: Console.WriteLine("\n********** Your Selection: Query Tweets By Username And Users By Tweet Count Range **********\n"); ts.queryTweetsByUsername(); ts.queryUsersByTweetCount(); break; case 7: Console.WriteLine("\n********** Your Selection: Stream UDF -- Aggregation Based on Tweet Count By Region **********\n"); us.aggregateUsersByTweetCountByRegion(); break; case 12: Console.WriteLine("\n********** Create Users **********\n"); us.createUsers(); break; case 23: Console.WriteLine("\n********** Create Tweets **********\n"); ts.createTweets(); break; default: Console.WriteLine("\n********** Invalid Selection **********\n"); break; } } } else { Console.Write("ERROR: Connection to Aerospike cluster failed! Please check IP & Port settings and try again!"); Console.ReadLine(); } } catch (AerospikeException e) { Console.WriteLine("AerospikeException - Message: " + e.Message); Console.WriteLine("AerospikeException - StackTrace: " + e.StackTrace); } catch (Exception e) { Console.WriteLine("Exception - Message: " + e.Message); Console.WriteLine("Exception - StackTrace: " + e.StackTrace); } finally { if (client != null && client.Connected) { // Close Aerospike server connection client.Close(); } Console.Write("\n\nINFO: Press any key to exit..."); Console.ReadLine(); } }