public static void Run() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout Key key = new Key("test", "MultiSet", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key, bin1, bin2); Record record = client.Get(policy, key); if (record != null) { foreach (KeyValuePair <string, object> entry in record.bins) { Console.WriteLine("Name=" + entry.Key + " Value=" + entry.Value); } } client.Close(); }
public static void Run() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); Key key = new Key("test", "MultiOps", "opkey"); Bin bin1 = new Bin("optintbin", 7); Bin bin2 = new Bin("optstringbin", "string value"); client.Put(policy, key, bin1, bin2); Bin bin3 = new Bin(bin1.name, 4); Bin bin4 = new Bin(bin2.name, "new string"); Record record = client.Operate(policy, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get()); var rec = client.Operate(policy, key, Operation.Get(), Operation.Delete()); }
public static void Run2() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout // Write single value. Key key = new Key("test", "myset", "mykey"); Bin bin = new Bin("mybin", "myvalue"); client.Put(policy, key, bin); Record record = client.Get(policy, key, "mybin"); if (record != null) { Console.WriteLine("Got name: " + record.GetValue("mybin")); } client.Close(); }
public IActionResult Index() { AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. // Write single or multiple values. Key key = new Key("test", "myset", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key, bin1, bin2); Record record = client.Get(policy, key, "name"); if (record != null) { Console.WriteLine("Got name: " + record.GetValue("name")); } client.Close(); return(View()); }
public JsonResult Create([FromBody] SynonymsPageViewModel synonymsModel) { //var synonymsModel = JsonConvert.DeserializeObject<SynonymsPageViewModel>(synonymsString); Synonyms synonym = new Synonyms(); var simplified = Simplify(synonymsModel.Phrase); synonym.Simplified = simplified; synonym.Phrase = synonymsModel.Phrase; synonym.RelatedWord = synonymsModel.RelatedWord; synonym.Tag = synonymsModel.Tag; var synonymsDb = db.Synonyms.Where(x => x.Phrase == synonymsModel.Phrase && x.RelatedWord == synonymsModel.RelatedWord).FirstOrDefault(); if (synonymsDb != null) { return(Json(new { MessageТype = MessageType.Info, Message = "Овој збор веќе постои" })); } try { // insert using (var db = new ApplicationDbContext()) { var synonyms = db.Set <Synonyms>(); synonyms.Add(synonym); db.SaveChanges(); } AerospikeClient client = new AerospikeClient(configuration["AppSettings:AerospikeClient"], 3000); //var _client = new MongoClient(); //var _database = _client.GetDatabase("SignLanguage"); // var _client = new MongoClient(); // var _database = _client.GetDatabase("SignLanguage"); // var _collection = _database.GetCollection<PhraseSynonymModel>("PhraseSynonyms"); PhraseSynonymModel model = new PhraseSynonymModel(); model.Simplified = simplified; model.Original = synonymsModel.Phrase; model.Synonym = synonymsModel.RelatedWord; WritePolicy policyWrite = new WritePolicy(); policyWrite.SetTimeout(50); // 50 millisecond timeout. Key keyWrite = new Key("sign-language", "Infinitive", simplified); Bin simpf = new Bin("Simplified", simplified); Bin original = new Bin("Original", synonymsModel.Phrase); Bin syn = new Bin("Infinitive", synonymsModel.RelatedWord); client.Put(policyWrite, keyWrite, simpf, original, syn); //_collection.InsertOne(inf); //_collection.InsertOne(model); return(Json(new { MessageТype = MessageType.Success, Message = "Успешно зачувување" })); } catch { return(Json(new { MessageТype = MessageType.Error, Message = "Грешка" })); } }
public IActionResult Index() { #region Initialize AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. #endregion #region Write Records // Write single value. Key key = new Key("test", "myset", "mykey"); Bin bin = new Bin("mybin", "myvalue"); client.Put(policy, key, bin); // Write multiple values. Key key2 = new Key("test", "myset", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key2, bin1, bin2); #endregion #region Read Records //Reading a Single or Multiple Value Record record = client.Get(policy, key, "name"); if (record != null) { Console.WriteLine("Got name: " + record.GetValue("name")); } Record recordMultiple = client.Get(policy, key); if (recordMultiple != null) { foreach (KeyValuePair <string, object> entry in recordMultiple.bins) { Console.WriteLine("Name=" + entry.Key + " Value=" + entry.Value); } } #endregion #region Delete Record Key keyDel = new Key("test", "myset", "mykey"); client.Delete(policy, keyDel); #endregion #region Cleaning Up //Call Close() when all transactions are finished and the application is ready to shutdown. //The AerospikeClient object can no longer be called after calling Close). client.Close(); #endregion return(View()); }
public void createTweet() { Console.WriteLine("\n********** Create Tweet **********\n"); Record userRecord = null; Key userKey = null; Key tweetKey = null; // Get username string username; Console.WriteLine("\nEnter username:"******"test", "users", username); userRecord = client.Get(null, userKey); if (userRecord != null) { int nextTweetCount = int.Parse(userRecord.GetValue("tweetcount").ToString()) + 1; // Get tweet string tweet; Console.WriteLine("Enter tweet for " + username + ":"); tweet = Console.ReadLine(); for (int i = 0; i < 10; i++) { nextTweetCount = int.Parse(userRecord.GetValue("tweetcount").ToString()) + 1; // Write record WritePolicy wPolicy = new WritePolicy(); //wPolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY; wPolicy.SetTimeout(500); // Create timestamp to store along with the tweet so we can query, index and report on it long ts = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();//DateTime.Now.ToString("yyyyMMddHHmmssffff"); //getTimeStamp(); tweetKey = new Key("test", "tweets", username + ":" + nextTweetCount); Bin bin1 = new Bin("tweet", tweet + i.ToString()); Bin bin2 = new Bin("ts", ts); Bin bin3 = new Bin("username", username); client.Put(wPolicy, tweetKey, bin1, bin2, bin3); Console.WriteLine("\nINFO: Tweet record created!"); // Update tweet count and last tweet'd timestamp in the user record client.Put(wPolicy, userKey, new Bin("tweetcount", nextTweetCount), new Bin("lasttweeted", ts)); } } else { Console.WriteLine("ERROR: User record not found!"); } } } //
public IActionResult Index() { #region Initialize AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. #endregion #region Write Records // Write single value. Key key = new Key("test", "myset", "mykey"); Bin bin = new Bin("mybin", "myvalue"); client.Put(policy, key, bin); // Write multiple values. Key key2 = new Key("test", "myset", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key2, bin1, bin2); #endregion #region Read Records //Reading a Single or Multiple Value Record record = client.Get(policy, key, "name"); if (record != null) { Console.WriteLine("Got name: " + record.GetValue("name")); } Record recordMultiple = client.Get(policy, key); if (recordMultiple != null) { foreach (KeyValuePair <string, object> entry in recordMultiple.bins) { Console.WriteLine("Name=" + entry.Key + " Value=" + entry.Value); } } #endregion #region Cleaning Up #endregion client.Close(); return(View()); }
public static void Run() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout Key key = new Key("test", "myset", "mykey"); client.Delete(policy, key); client.Close(); }
public IActionResult Index() { AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. client.Close(); return(View()); }
public IActionResult Index() { AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. // Write single value. Key key = new Key("test", "myset", "mykey"); Bin bin = new Bin("mybin", "myvalue"); client.Put(policy, key, bin); client.Close(); return(View()); }
public IActionResult Index() { AerospikeClient client = new AerospikeClient(new ClientPolicy(), "127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. // Write single or multiple values. Key key = new Key("test", "myset", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key, bin1, bin2); client.Close(); return(View()); }
public static void Run() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout Key key = new Key("test", "Add", "mykey"); string binName = "addbin"; // Delete record if it already exists. client.Delete(null, key); // Perform some adds and check results. Bin bin = new Bin(binName, 10); client.Add(null, key, bin); bin = new Bin(binName, 5); client.Add(null, key, bin); Record record = client.Get(null, key, bin.name); //AssertBinEqual(key, record, bin.name, 15); Console.WriteLine(record.GetInt(binName)); // test add and get combined. bin = new Bin(binName, 30); record = client.Operate(null, key, Operation.Add(bin), Operation.Get(bin.name)); Console.WriteLine(record.GetInt(binName)); client.Close(); }
public IActionResult Index() { #region Initialize AerospikeClient client = new AerospikeClient("127.0.0.1", 3000); // Initialize policy. WritePolicy policy = new WritePolicy(); policy.SetTimeout(50); // 50 millisecond timeout. #endregion #region Key-Value Store #region Write Records // Write single value. Key key = new Key("test", "myset", "mykey"); Bin bin = new Bin("mybin", "myvalue"); client.Put(policy, key, bin); // Write multiple values. Key key2 = new Key("test", "myset", "mykey"); Bin bin1 = new Bin("name", "John"); Bin bin2 = new Bin("age", 25); client.Put(policy, key2, bin1, bin2); #endregion #region Read Records //Reading a Single or Multiple Value Record record = client.Get(policy, key, "name"); if (record != null) { Console.WriteLine("Got name: " + record.GetValue("name")); } Record recordMultiple = client.Get(policy, key); if (recordMultiple != null) { foreach (KeyValuePair <string, object> entry in recordMultiple.bins) { Console.WriteLine("Name=" + entry.Key + " Value=" + entry.Value); } } #endregion #region Delete Record Key keyDel = new Key("test", "myset", "mykey"); client.Delete(policy, keyDel); #endregion #region Batch Reads //Multiple records can be read in a single batch call. Key[] keysBach = new Key[size]; for (int i = 0; i < 1000; i++) { keys[i] = new Key("test", "myset", (i + 1)); } Record[] records = client.Get(policy, keysBach); #endregion #region Multiple Ops Key key = new Key("test", "demoset", "opkey"); Bin bin1 = new Bin("optintbin", 7); Bin bin2 = new Bin("optstringbin", "string value"); client.Put(policy, key, bin1, bin2); Bin bin3 = new Bin(bin1.name, 4); Bin bin4 = new Bin(bin2.name, "new string"); Record record = client.Operate(policy, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get()); #endregion #endregion #region Cleaning Up //Call Close() when all transactions are finished and the application is ready to shutdown. //The AerospikeClient object can no longer be called after calling Close). client.Close(); #endregion return(View()); }
public static void WriteListMapUsingUdf() { AerospikeClient client = new AerospikeClient("172.28.128.3", 3000); ClientPolicy policy1 = new ClientPolicy(); policy1.maxConnsPerNode = 1000; try { Key key = new Key("test", "WriteListSet", "udfkey5"); List <object> inner = new List <object>(); inner.Add("string2"); inner.Add(8L); //List<object> PersonInner = new List<object>(); //inner.Add(1L); //inner.Add("Ahmet"); //inner.Add("Sekmen"); List <object> PersonInner = new List <object>(); for (int i = 0; i < 99000; i++) { PersonInner.Add(i); PersonInner.Add("Ahmet"); PersonInner.Add("Sekmen"); } List <Person> PersonNesne = new List <Person>(); PersonNesne.Add(new Person() { Id = 2, Name = "anastasia", Surname = "Sekmen" }); PersonNesne.Add(new Person() { Id = 3, Name = "anastasia", Surname = "Sekmen" }); Dictionary <object, object> innerMap = new Dictionary <object, object>(); innerMap["a"] = 1L; innerMap[2L] = "b"; innerMap["list"] = inner; //Dictionary<object, object> personMap = new Dictionary<object, object>(); //innerMap["a"] = 1L; //innerMap[2L] = "b"; //innerMap["list"] = inner; List <object> list = new List <object>(); list.Add("string1"); list.Add(4L); list.Add(inner); list.Add(innerMap); list.Add(PersonInner); list.Add(PersonNesne); string binName = "udfbin5"; WritePolicy policy = new WritePolicy(); policy.SetTimeout(5000); client.Execute(policy, key, "example", "writeBin", Value.Get(binName), Value.Get(list)); IList received = (IList)client.Execute(policy, key, "example", "readBin", Value.Get(binName)); //Assert.IsNotNull(received); //Assert.AreEqual(list.Count, received.Count); //Assert.AreEqual(list[0], received[0]); //Assert.AreEqual(list[1], received[1]); //CollectionAssert.AreEqual((IList)list[2], (IList)received[2]); IDictionary exp = (IDictionary)list[3]; IDictionary rec = (IDictionary)received[3]; //Assert.AreEqual(exp["a"], rec["a"]); //Assert.AreEqual(exp[2L], rec[2L]); //CollectionAssert.AreEqual((IList)exp["list"], (IList)rec["list"]); } finally { client.Close(); } }