public Task SetAsync(string key, byte[] value, DistributedCacheEntryOptions options, CancellationToken token = default(CancellationToken)) { Connect(); SetExpiration(options, out int exp, out int expBin); WritePolicy policy = null; if (exp > 0) { // Use non-default record expiration. policy = new WritePolicy(client.writePolicyDefault) { expiration = exp }; } WriteHandler listener = new WriteHandler(token); if (expBin >= 0) { client.Put(policy, listener, new Key(config.Namespace, config.Set, key), new Bin(config.BinName, value), new Bin(ExpirationBinName, expBin)); } else { client.Put(policy, listener, new Key(config.Namespace, config.Set, key), new Bin(config.BinName, value)); } return(listener.Task); }
public void AddOrUpdate(InstanceInfo instanceInfo) { if (instanceInfo == null) { return; } var policy = new WritePolicy() { recordExistsAction = RecordExistsAction.REPLACE }; var key = new Key(_settings[Keystore.AerospikeKeys.InstanceStore.Namespace], _settings[Keystore.AerospikeKeys.InstanceStore.Set], instanceInfo.GetUniqueId()); var regionBin = new Bin(Keystore.AerospikeKeys.InstanceStore.InstanceIdBin, instanceInfo.RegionId); var zoneBin = new Bin(Keystore.AerospikeKeys.InstanceStore.InstanceIdBin, instanceInfo.ZoneId); var instanceBin = new Bin(Keystore.AerospikeKeys.InstanceStore.InstanceIdBin, instanceInfo.InstanceId); var timestampBin = new Bin(Keystore.AerospikeKeys.InstanceStore.TimestampBin, instanceInfo.UpdateTimestamp.ToString("T")); using (AerospikeClient client = GetClient()) { client.Put(policy, key, regionBin, zoneBin, instanceBin, timestampBin); } }
public void Set(string key, byte[] value, DistributedCacheEntryOptions options) { Connect(); SetExpiration(options, out int exp, out int expBin); WritePolicy policy = null; if (exp > 0) { // Use non-default record expiration. policy = new WritePolicy(client.writePolicyDefault) { expiration = exp }; } if (expBin >= 0) { client.Put(policy, new Key(config.Namespace, config.Set, key), new Bin(config.BinName, value), new Bin(ExpirationBinName, expBin)); } else { client.Put(policy, new Key(config.Namespace, config.Set, key), new Bin(config.BinName, value)); } }
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()); }
private void CreateRecordIfMissing(AerospikeSettings settings, Key recordKey) { var client = GetClient(settings); if (client.Exists(null, new Key[] { recordKey }[0])) { return; } var writePolicy = new WritePolicy() { recordExistsAction = RecordExistsAction.CREATE_ONLY, expiration = 3600, sendKey = true }; try { client.Put(writePolicy, recordKey, new Bin[2] { new Bin(Keystore.AerospikeKeys.BinNames.ReadLocks, 0), new Bin(Keystore.AerospikeKeys.BinNames.WriteLocks, 0) }); } catch (AerospikeException aex) { if (aex.Result != 5) { throw; } } }
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 Main(string[] args) { var client = Connect(); var policy = new Policy(); var writePolicy = new WritePolicy(); var batchPolicy = new BatchPolicy(); //NOTE: adjust the timeout value depending on your demo machine writePolicy.timeout = 1000; var key = new Key("test", "myset", "mykey"); WriteSingleValue(client, writePolicy, key); CheckKeyExists(client, policy, key); AddSingleValue(client, writePolicy); WriteMultipleValues(client, writePolicy, key); WriteValueWithTtl(client); ReadAllValuesForKey(client, policy, key); ReadSomeValuesForKey(client, policy, key); DeleteValue(client, writePolicy, key); DeleteRecord(client, writePolicy, key); AddRecords(client, writePolicy); BatchReadRecords(client, batchPolicy); MultiOps(client, writePolicy, key); client.Close(); }
public QueryKeyInit() { Policy policy = new Policy(); policy.totalTimeout = 0; // Do not timeout on index create. try { IndexTask itask = client.CreateIndex(policy, args.ns, args.set, TestQueryKey.indexName, TestQueryKey.binName, IndexType.NUMERIC); itask.Wait(); } catch (AerospikeException ae) { if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS) { throw; } } WritePolicy writePolicy = new WritePolicy(); writePolicy.sendKey = true; for (int i = 1; i <= TestQueryKey.size; i++) { Key key = new Key(args.ns, args.set, TestQueryKey.keyPrefix + i); Bin bin = new Bin(TestQueryKey.binName, i); client.Put(writePolicy, key, bin); } }
public WriteCommand(WritePolicy policy, Key key, Bin[] bins, Operation.Type operation) { this.policy = policy; this.key = key; this.bins = bins; this.operation = operation; }
public AsyncTouch(AsyncTouch other) : base(other) { this.writePolicy = other.writePolicy; this.listener = other.listener; this.key = other.key; }
} //aggregateUsersByTweetCountByRegion public void createUsers(AerospikeClient client) { string[] regions = { "n", "s", "e", "w" }; string username; int start = 0; int end = 10000; int totalUsers = end - start; Random rnd1 = new Random(); Random rnd2 = new Random(); Random rnd3 = new Random(); WritePolicy wPolicy = new WritePolicy(); wPolicy.recordExistsAction = RecordExistsAction.UPDATE; Console.WriteLine("\nCreate " + totalUsers + " users in set 'testusers'. Press any key to continue..."); Console.ReadLine(); for (int j = start; j <= end; j++) { // Write user record username = "******" + j; Key key = new Key("test", "testusers", username); Bin bin1 = new Bin("username", "user" + j); Bin bin2 = new Bin("region", regions[rnd2.Next(0, 4)]); Bin bin3 = new Bin("tweetcount", rnd3.Next(0, 20)); client.Put(wPolicy, key, bin1, bin2, bin3); Console.WriteLine("\nCreated " + username); } Console.WriteLine("\nDone creating " + totalUsers + "!"); } //createUsers
public DeleteCommand(Cluster cluster, WritePolicy policy, Key key) { this.cluster = cluster; this.policy = policy; this.key = key; this.partition = new Partition(key); }
private void RunReplaceOnlyExample(AerospikeClient client, Arguments args) { Key key = new Key(args.ns, args.set, "replaceonlykey"); Bin bin = new Bin("bin", "value"); // Delete record if it already exists. client.Delete(args.writePolicy, key); console.Info("Replace record requiring that it exists: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey); try { WritePolicy policy = new WritePolicy(); policy.recordExistsAction = RecordExistsAction.REPLACE_ONLY; client.Put(policy, key, bin); console.Error("Failure. This command should have resulted in an error."); } catch (AerospikeException ae) { if (ae.Result == ResultCode.KEY_NOT_FOUND_ERROR) { console.Info("Success. Key not found error returned as expected."); } else { throw ae; } } }
public void Replace() { Key key = new Key(args.ns, args.set, "replacekey"); Bin bin1 = new Bin("bin1", "value1"); Bin bin2 = new Bin("bin2", "value2"); Bin bin3 = new Bin("bin3", "value3"); client.Put(null, key, bin1, bin2); WritePolicy policy = new WritePolicy(); policy.recordExistsAction = RecordExistsAction.REPLACE; client.Put(policy, key, bin3); Record record = client.Get(null, key); AssertRecordFound(key, record); if (record.GetValue(bin1.name) != null) { Assert.Fail(bin1.name + " found when it should have been deleted."); } if (record.GetValue(bin2.name) != null) { Assert.Fail(bin2.name + " found when it should have been deleted."); } AssertBinEqual(key, record, bin3); }
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 AsyncTouch(AsyncCluster cluster, WritePolicy writePolicy, WriteListener listener, Key key) : base(cluster, writePolicy, new Partition(key), false) { this.writePolicy = writePolicy; this.listener = listener; this.key = key; }
public void Touch() { Key key = new Key(args.ns, args.set, "touchkey"); Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue"); WritePolicy writePolicy = new WritePolicy(); writePolicy.expiration = 2; client.Put(writePolicy, key, bin); writePolicy.expiration = 5; Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader()); AssertRecordFound(key, record); Assert.AreNotEqual(0, record.expiration); Util.Sleep(3000); record = client.Get(null, key, bin.name); AssertRecordFound(key, record); Util.Sleep(4000); record = client.Get(null, key, bin.name); Assert.IsNull(record); }
public AsyncDelete(AsyncDelete other) : base(other) { this.writePolicy = other.writePolicy; this.listener = other.listener; this.key = other.key; }
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 void Initialize() { predAEq1BPolicy = new BatchPolicy(); predAEq1RPolicy = new Policy(); predAEq1WPolicy = new WritePolicy(); predAEq1BPolicy.SetPredExp( PredExp.IntegerBin(binAName), PredExp.IntegerValue(1), PredExp.IntegerEqual()); predAEq1RPolicy.SetPredExp( PredExp.IntegerBin(binAName), PredExp.IntegerValue(1), PredExp.IntegerEqual()); predAEq1WPolicy.SetPredExp( PredExp.IntegerBin(binAName), PredExp.IntegerValue(1), PredExp.IntegerEqual()); client.Delete(null, keyA); client.Delete(null, keyB); client.Put(null, keyA, binA1); client.Put(null, keyB, binA2); }
public DeleteCommand(Cluster cluster, WritePolicy writePolicy, Key key) : base(cluster, writePolicy) { this.writePolicy = writePolicy; this.key = key; this.partition = Partition.Write(cluster, writePolicy, key); }
private static void WriteValueWithTtl(AerospikeClient client) { var writePolicy = new WritePolicy { expiration = 2 }; var ttlKey = new Key("test", "myTtlSet", "myTtlKey"); var bin = new Bin("gender", "female"); client.Put(writePolicy, ttlKey, bin); var policy = new Policy(); CheckKeyExists(client, policy, ttlKey); Console.WriteLine("sleeping for 4 seconds"); try { Thread.Sleep(4000); } catch (ThreadInterruptedException e) { Console.WriteLine(e + ""); } CheckKeyExists(client, policy, ttlKey); Console.WriteLine(""); }
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 AsyncDelete(AsyncCluster cluster, WritePolicy writePolicy, Key key, DeleteListener listener) : base(cluster, writePolicy, false) { this.writePolicy = writePolicy; this.listener = listener; this.key = key; this.partition = Partition.Write(cluster, policy, key); }
public AsyncTouch(AsyncCluster cluster, WritePolicy policy, WriteListener listener, Key key) : base(cluster) { this.policy = policy; this.listener = listener; this.key = key; this.partition = new Partition(key); }
public AsyncDelete(AsyncCluster cluster, WritePolicy policy, Key key, DeleteListener listener) : base(cluster) { this.policy = policy; this.listener = listener; this.key = key; this.partition = new Partition(key); }
} //createTweet private void updateUser(AerospikeClient client, Key userKey, WritePolicy policy, long ts, int tweetCount) { // Update tweet count and last tweet'd timestamp in the user record client.Put(policy, userKey, new Bin("tweetcount", tweetCount), new Bin("lasttweeted", ts)); Console.WriteLine("INFO: The tweet count now is: " + tweetCount); //updateUserUsingOperate(client, userKey, policy, ts); } //updateUser
private static void DeleteRecord(AerospikeClient client, WritePolicy policy, Key key) { client.Delete(policy, key); CheckKeyExists(client, policy, key); Console.WriteLine("Deleted this record: " + key); Console.WriteLine(""); }
public WriteHandler(AsyncPutGet parent, AsyncClient client, WritePolicy policy, Key key, Bin bin) { this.parent = parent; this.client = client; this.policy = policy; this.key = key; this.bin = bin; }
public WriteRequest(AbstractClient client, string collection, ICache <T> cache, ISyncQueue queue, WritePolicy policy) : base(client) { this.Collection = collection; this.Cache = cache; this.SyncQueue = queue; this.Policy = policy; }
public WriteCommand(Cluster cluster, WritePolicy policy, Key key, Bin[] bins, Operation.Type operation) { this.policy = policy; this.key = key; this.partition = Partition.Write(cluster, policy, key); this.bins = bins; this.operation = operation; }
/// <summary> /// Copy write policy from another write policy. /// </summary> public WritePolicy(WritePolicy other) : base(other) { this.recordExistsAction = other.recordExistsAction; this.generationPolicy = other.generationPolicy; this.commitLevel = other.commitLevel; this.generation = other.generation; this.expiration = other.expiration; }
public WriteCommand(Cluster cluster, WritePolicy policy, Key key, Bin[] bins, Operation.Type operation) { this.cluster = cluster; this.policy = policy; this.key = key; this.partition = new Partition(key); this.bins = bins; this.operation = operation; }
public AsyncWrite(AsyncCluster cluster, WritePolicy policy, WriteListener listener, Key key, Bin[] bins, Operation.Type operation) : base(cluster) { this.policy = policy; this.listener = listener; this.key = key; this.partition = new Partition(key); this.bins = bins; this.operation = operation; }
public ServerCommand(Node node, WritePolicy policy, Statement statement) : base(node, true) { this.writePolicy = policy; this.statement = statement; }