private void RunPutGet(AsyncClient client, Arguments args, Key key, Bin bin)
        {
            console.Info("Put: namespace={0} set={1} key={2} value={3}",
                key.ns, key.setName, key.userKey, bin.value);

            client.Put(args.writePolicy, new WriteHandler(this, client, args.writePolicy, key, bin), key, bin);
        }
        /// <summary>
        /// Demonstrate multiple operations on a single record in one call.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            // Write initial record.
            Key key = new Key(args.ns, args.set, "opkey");
            Bin bin1 = new Bin("optintbin", 7);
            Bin bin2 = new Bin("optstringbin", "string value");
            console.Info("Put: namespace={0} set={1} key={2} binname1={3} binvalue1={4} binname1={5} binvalue1={6}",
                key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
            client.Put(args.writePolicy, key, bin1, bin2);

            // Add integer, write new string and read record.
            Bin bin3 = new Bin(bin1.name, 4);
            Bin bin4 = new Bin(bin2.name, "new string");
            console.Info("Add: " + bin3.value);
            console.Info("Write: " + bin4.value);
            console.Info("Read:");
            Record record = client.Operate(args.writePolicy, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get());

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            ValidateBin(key, record, bin3.name, 11L, record.GetValue(bin3.name));
            ValidateBin(key, record, bin4.name, bin4.value.ToString(), record.GetValue(bin4.name));
        }
        public void ListComplex()
        {
            Key key = new Key(args.ns, args.set, "listkey2");
            client.Delete(null, key);

            string geopoint = "{ \"type\": \"Point\", \"coordinates\": [0.00, 0.00] }";

            byte[] blob = new byte[] {3, 52, 125};
            List<object> list = new List<object>();
            list.Add("string1");
            list.Add(2);
            list.Add(blob);
            list.Add(Value.GetAsGeoJSON(geopoint));

            Bin bin = new Bin(args.GetBinName("listbin2"), list);
            client.Put(null, key, bin);

            Record record = client.Get(null, key, bin.name);
            IList receivedList = (IList)record.GetValue(bin.name);

            Assert.AreEqual(4, receivedList.Count);
            Assert.AreEqual("string1", receivedList[0]);
            // Server convert numbers to long, so must expect long.
            Assert.AreEqual(2L, receivedList[1]);
            CollectionAssert.AreEqual(blob, (byte[])receivedList[2]);
            Assert.AreEqual(Value.GetAsGeoJSON(geopoint), (Value)receivedList[3]);
        }
        public static void Prepare(TestContext testContext)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            RegisterTask rtask = client.Register(null, assembly, "Aerospike.Test.Resources.record_example.lua", "record_example.lua", Language.LUA);
            rtask.Wait();

            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.STRING, IndexCollectionType.MAPKEYS);
            task.Wait();

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Dictionary<string, string> map = new Dictionary<string, string>();

                map[mapKeyPrefix + 1] = mapValuePrefix + i;
                if (i % 2 == 0)
                {
                    map[mapKeyPrefix + 2] = mapValuePrefix + i;
                }
                if (i % 3 == 0)
                {
                    map[mapKeyPrefix + 3] = mapValuePrefix + i;
                }

                Bin bin = new Bin(binName, map);
                client.Put(null, key, bin);
            }
        }
        /// <summary>
        /// Write array of integers using standard C# serializer.
        /// </summary>
        public virtual void TestArray(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "serialarraykey");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            console.Info("Initialize array");

            int[] array = new int[10000];

            for (int i = 0; i < 10000; i++)
            {
                array[i] = i * i;
            }

            Bin bin = new Bin(args.GetBinName("serialbin"), (object)array);

            // Do a test that pushes this complex object through the serializer
            console.Info("Write array using serializer.");
            client.Put(args.writePolicy, key, bin);

            console.Info("Read array using serializer.");
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            int[] received;

            try
            {
                received = (int[])record.GetValue(bin.name);
            }
            catch (Exception)
            {
                throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
                    key.ns, key.setName, key.userKey, bin.name));
            }

            if (received.Length != 10000)
            {
                throw new Exception(string.Format("Array length mismatch: Expected={0:D} Received={1:D}",
                    10000, received.Length));
            }

            for (int i = 0; i < 10000; i++)
            {
                if (received[i] != i * i)
                {
                    throw new Exception(string.Format("Mismatch: index={0:D} expected={1:D} received={2:D}",
                        i, i * i, received[i]));
                }
            }

            console.Info("Read array successful.");
        }
        public void InsertByKey()
        {
            int i = 0;
            for (int x = 1; x <= TestQueryEngine.RECORD_COUNT; x++)
            {
                String keyString = "selector-test:" + x;

                Bin name = new Bin("name", "name:" + x);
                Bin age = new Bin("age", ages[i]);
                Bin colour = new Bin("color", colours[i]);
                Bin animal = new Bin("animal", animals[i]);
                List<Bin> bins = new List<Bin>() { name, age, colour, animal };

                Key key = new Key(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, keyString);
                this.client.Delete(null, key);

                KeyQualifier kq = new KeyQualifier(Value.Get(keyString));
                Statement stmt = new Statement();
                stmt.Namespace = TestQueryEngine.NAMESPACE;
                stmt.SetName = TestQueryEngine.SET_NAME;

                queryEngine.Insert(stmt, kq, bins);

                Record record = this.client.Get(null, key);
                Assert.NotNull(record);
                i++;
                if (i == 5)
                    i = 0;
            }
        }
        public void PutGet()
        {
            Key key = new Key(args.ns, args.set, "putgetkey");
            Record record;

            if (args.singleBin)
            {
                Bin bin = new Bin("", "value");

                client.Put(null, key, bin);
                record = client.Get(null, key);
                AssertBinEqual(key, record, bin);
            }
            else {
                Bin bin1 = new Bin("bin1", "value1");
                Bin bin2 = new Bin("bin2", "value2");

                client.Put(null, key, bin1, bin2);
                record = client.Get(null, key);
                AssertBinEqual(key, record, bin1);
                AssertBinEqual(key, record, bin2);
            }

            record = client.GetHeader(null, key);
            AssertRecordFound(key, record);

            // Generation should be greater than zero.  Make sure it's populated.
            if (record.generation == 0)
            {
                Assert.Fail("Invalid record header: generation=" + record.generation + " expiration=" + record.expiration);
            }
        }
        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);
        }
        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);
            }
        }
 private void add()
 {
     // C# Add Example
     Key userKey = new Key("test", "users", "user1234");
     Bin bin1 = new Bin("count", 2);
     Bin bin2 = new Bin("count", 3);
     client.Add(null, userKey, bin2);
 }
        public void AsyncPutGet()
        {
            Key key = new Key(args.ns, args.set, "putgetkey1");
            Bin bin = new Bin(binName, "value1");

            client.Put(null, new WriteHandler(this, client, key, bin), key, bin);
            WaitTillComplete();
        }
Example #12
0
        /// <summary>
        /// Add integer values.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "addkey");
            string binName = args.GetBinName("addbin");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            // Perform some adds and check results.
            Bin bin = new Bin(binName, 10);
            console.Info("Initial add will create record.  Initial value is " + bin.value + '.');
            client.Add(args.writePolicy, key, bin);

            bin = new Bin(binName, 5);
            console.Info("Add " + bin.value + " to existing record.");
            client.Add(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            // The value received from the server is an unsigned byte stream.
            // Convert to an integer before comparing with expected.
            int received = record.GetInt(bin.name);
            int expected = 15;

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }

            // Demonstrate add and get combined.
            bin = new Bin(binName, 30);
            console.Info("Add " + bin.value + " to existing record.");
            record = client.Operate(args.writePolicy, key, Operation.Add(bin), Operation.Get(bin.name));

            expected = 45;
            received = record.GetInt(bin.name);

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
        public void AsyncUDF()
        {
            Key key = new Key(args.ns, args.set, "audfkey1");
            Bin bin = new Bin(binName, binValue);

            // Write bin
            client.Execute(null, new WriteHandler(this, key), key, "record_example", "writeBin", Value.Get(bin.name), bin.value);
            WaitTillComplete();
        }
 private static void AddSingleValue(AerospikeClient client,
         WritePolicy writePolicy)
 {
     var newKey = new Key("test", "myAddSet", "myAddKey");
     var counter = new Bin("mybin", 1);
     client.Add(writePolicy, newKey, counter);
     Console.WriteLine("Wrote this additional value (or bin):  " + newKey);
     Console.WriteLine("");
 }
        /// <summary>
        /// Drop a bin from a record.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            if (args.singleBin)
            {
                console.Info("Delete bin is not applicable to single bin servers.");
                return;
            }

            console.Info("Write multi-bin record.");
            Key key = new Key(args.ns, args.set, "delbinkey");
            string binName1 = args.GetBinName("bin1");
            string binName2 = args.GetBinName("bin2");
            Bin bin1 = new Bin(binName1, "value1");
            Bin bin2 = new Bin(binName2, "value2");
            client.Put(args.writePolicy, key, bin1, bin2);

            console.Info("Delete one bin in the record.");
            bin1 = Bin.AsNull(binName1); // Set bin value to null to drop bin.
            client.Put(args.writePolicy, key, bin1);

            console.Info("Read record.");
            Record record = client.Get(args.policy, key, bin1.name, bin2.name, "bin3");

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            foreach (KeyValuePair<string, object> entry in record.bins)
            {
                console.Info("Received: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, entry.Key, entry.Value);
            }

            bool valid = true;

            if (record.GetValue("bin1") != null)
            {
                console.Error("bin1 still exists.");
                valid = false;
            }

            object v2 = record.GetValue("bin2");

            if (v2 == null || !v2.Equals("value2"))
            {
                console.Error("bin2 value mismatch.");
                valid = false;
            }

            if (valid)
            {
                console.Info("Bin delete successful");
            }
        }
        public static void WriteRecords(TestContext testContext)
        {
            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, valuePrefix + i);

                client.Put(null, key, bin);
            }
        }
        /// <summary>
        /// Asynchronously write and read a bin using alternate methods.
        /// </summary>
        public override void RunExample(AsyncClient client, Arguments args)
        {
            completed = false;
            Key key = new Key(args.ns, args.set, "putgetkey");
            Bin bin = new Bin(args.GetBinName("putgetbin"), "value");

            RunPutGet(client, args, key, bin);
            WaitTillComplete();

            RunPutGetWithTask(client, args, key, bin);
        }
Example #18
0
        public static void AssertBinEqual(Key key, Record record, Bin bin)
        {
            AssertRecordFound(key, record);

            object received = record.GetValue(bin.name);
            object expected = bin.value.Object;

            if (received == null || !received.Equals(expected))
            {
                Assert.Fail("Data mismatch: Expected " + expected + ". Received " + received);
            }
        }
        public void AsyncQuery()
        {
            WriteHandler handler = new WriteHandler(this);

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, i);
                client.Put(null, handler, key, bin);
            }
            WaitTillComplete();
        }
Example #20
0
        /// <summary>
        /// Demonstrate touch command.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "touchkey");
            Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue");

            console.Info("Create record with 2 second expiration.");
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            console.Info("Touch same record with 5 second expiration.");
            writePolicy.expiration = 5;
            Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader());

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, null));
            }

            if (record.expiration == 0)
            {
                throw new Exception(string.Format("Failed to get record expiration: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Sleep 3 seconds.");
            Thread.Sleep(3000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Success. Record still exists.");
            console.Info("Sleep 4 seconds.");
            Thread.Sleep(4000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Success. Record expired as expected.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
        public static void WriteRecords(TestContext testContext)
        {
            WritePolicy policy = new WritePolicy();
            policy.expiration = 2592000;

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, valuePrefix + i);

                client.Put(policy, key, bin);
            }
        }
Example #22
0
        /// <summary>
        /// Write and twice read a bin value, demonstrating record expiration.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "expirekey");
            Bin bin = new Bin(args.GetBinName("expirebin"), "expirevalue");

            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expiration=2",
                key.ns, key.setName, key.userKey, bin.name, bin.value);

            // Specify that record expires 2 seconds after it's written.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            // Read the record before it expires, showing it's there.
            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            object received = record.GetValue(bin.name);
            string expected = bin.value.ToString();

            if (received.Equals(expected))
            {
                console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                throw new Exception(string.Format("Expire mismatch: Expected {0}. Received {1}.", expected, received));
            }

            // Read the record after it expires, showing it's gone.
            console.Info("Sleeping for 3 seconds ...");
            Thread.Sleep(3 * 1000);
            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Expiry successful. Record not found.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
        public void AsyncPutGetWithTask()
        {
            Key key = new Key(args.ns, args.set, "putgetkey2");
            Bin bin = new Bin(binName, "value2");

            CancellationTokenSource cancel = new CancellationTokenSource();
            Task taskput = client.Put(null, cancel.Token, key, bin);
            taskput.Wait();

            Task<Record> taskget = client.Get(null, cancel.Token, key);
            taskget.Wait();

            TestSync.AssertBinEqual(key, taskget.Result, bin);
        }
        public void Generation()
        {
            Key key = new Key(args.ns, args.set, "genkey");
            string binName = args.GetBinName("genbin");

            // Delete record if it already exists.
            client.Delete(null, key);

            // Set some values for the same record.
            Bin bin = new Bin(binName, "genvalue1");

            client.Put(null, key, bin);

            bin = new Bin(binName, "genvalue2");

            client.Put(null, key, bin);

            // Retrieve record and its generation count.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Set record and fail if it's not the expected generation.
            bin = new Bin(binName, "genvalue3");

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
            writePolicy.generation = record.generation;
            client.Put(writePolicy, key, bin);

            // Set record with invalid generation and check results .
            bin = new Bin(binName, "genvalue4");
            writePolicy.generation = 9999;

            try
            {
                client.Put(writePolicy, key, bin);
                Assert.Fail("Should have received generation error instead of success.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result != ResultCode.GENERATION_ERROR)
                {
                    Assert.Fail("Unexpected return code: namespace=" + key.ns + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name + " value=" + bin.value + " code=" + ae.Result);
                }
            }

            // Verify results.
            record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin.name, "genvalue3");
        }
        public static void Prepare(TestContext testContext)
        {
            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC);
            task.Wait();

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, i);
                client.Put(null, key, bin);
            }
        }
        public void ListMapCombined()
        {
            Key key = new Key(args.ns, args.set, "listmapkey");
            client.Delete(null, key);

            byte[] blob = new byte[] {3, 52, 125};
            List<object> inner = new List<object>();
            inner.Add("string2");
            inner.Add(5);

            Dictionary<object, object> innerMap = new Dictionary<object, object>();
            innerMap["a"] = 1;
            innerMap[2] = "b";
            innerMap[3] = blob;
            innerMap["list"] = inner;

            List<object> list = new List<object>();
            list.Add("string1");
            list.Add(8);
            list.Add(inner);
            list.Add(innerMap);

            Bin bin = new Bin(args.GetBinName("listmapbin"), list);
            client.Put(null, key, bin);

            Record record = client.Get(null, key, bin.name);
            IList received = (IList) record.GetValue(bin.name);

            Assert.AreEqual(4, received.Count);
            Assert.AreEqual("string1", received[0]);
            // Server convert numbers to long, so must expect long.
            Assert.AreEqual(8L, received[1]);

            IList receivedInner = (IList)received[2];
            Assert.AreEqual(2, receivedInner.Count);
            Assert.AreEqual("string2", receivedInner[0]);
            Assert.AreEqual(5L, receivedInner[1]);

            IDictionary receivedMap = (IDictionary)received[3];
            Assert.AreEqual(4, receivedMap.Count);
            Assert.AreEqual(1L, receivedMap["a"]);
            Assert.AreEqual("b", receivedMap[2L]);
            CollectionAssert.AreEqual(blob, (byte[])receivedMap[3L]);

            IList receivedInner2 = (IList)receivedMap["list"];
            Assert.AreEqual(2, receivedInner2.Count);
            Assert.AreEqual("string2", receivedInner2[0]);
            Assert.AreEqual(5L, receivedInner2[1]);
        }
        public void Operate()
        {
            // Write initial record.
            Key key = new Key(args.ns, args.set, "opkey");
            Bin bin1 = new Bin("optintbin", 7);
            Bin bin2 = new Bin("optstringbin", "string value");
            client.Put(null, key, bin1, bin2);

            // Add integer, write new string and read record.
            Bin bin3 = new Bin(bin1.name, 4);
            Bin bin4 = new Bin(bin2.name, "new string");
            Record record = client.Operate(null, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get());
            AssertBinEqual(key, record, bin3.name, 11);
            AssertBinEqual(key, record, bin4);
        }
        private void ServerSideExists(AerospikeClient client, Arguments args)
        {
            console.Info("Write list.");
            List<int> list = new List<int>();
            list.Add(64);
            list.Add(3702);
            list.Add(-5);

            Key key = new Key(args.ns, args.set, "udfkey7");
            Bin bin = new Bin("udfbin7", list);
            client.Put(args.writePolicy, key, bin);

            ServerSideExists(client, args.writePolicy, key, bin, 3702, true);
            ServerSideExists(client, args.writePolicy, key, bin, 65, false);
        }
 protected override void WriteRecord(WritePolicy policy, Key key, Bin bin)
 {
     if (shared.writeLatency != null)
     {
         Stopwatch watch = Stopwatch.StartNew();
         client.Put(policy, key, bin);
         double elapsed = watch.Elapsed.TotalMilliseconds;
         OnWriteSuccess(elapsed);
     }
     else
     {
         client.Put(policy, key, bin);
         OnWriteSuccess();
     }
 }
Example #30
0
        private void RunReplaceExample(AerospikeClient client, Arguments args)
        {
            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");

            console.Info("Put: namespace={0} set={1} key={2} bin1={3} value1={4} bin2={5} value2={6}",
                key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);

            client.Put(args.writePolicy, key, bin1, bin2);

            console.Info("Replace with: namespace={0} set={1} key={2} bin={3} value={4}",
                key.ns, key.setName, key.userKey, bin3.name, bin3.value);

            WritePolicy policy = new WritePolicy();
            policy.recordExistsAction = RecordExistsAction.REPLACE;
            client.Put(policy, key, bin3);

            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

            Record record = client.Get(args.policy, key);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            if (record.GetValue(bin1.name) == null)
            {
                console.Info(bin1.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin1.name + " found when it should have been deleted.");
            }

            if (record.GetValue(bin2.name) == null)
            {
                console.Info(bin2.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin2.name + " found when it should have been deleted.");
            }
            ValidateBin(key, bin3, record);
        }
Example #31
0
        private static void AerospikeWriteMethod(User user)
        {
            using (var client = new AC.AerospikeClient(Config.DOCKER_MACHINE_IP, 3000))
            {
                if (!client.Connected)
                {
                    Console.WriteLine("Aerospike ERROR: Connection failed!");
                    return;
                }

                var wPolicy = new AC.WritePolicy
                {
                    recordExistsAction = AC.RecordExistsAction.UPDATE
                };

                var key     = new AC.Key("test", "users", user.Id);
                var binId   = new AC.Bin("id", user.Id);
                var binName = new AC.Bin("name", user.Name);
                var binAge  = new AC.Bin("age", user.Age);

                client.Put(wPolicy, key, binId, binName, binAge);
            }
        }
 private void EstimateOperationSize(Bin bin)
 {
     dataOffset += ByteUtil.EstimateSizeUtf8(bin.name) + OPERATION_HEADER_SIZE;
     dataOffset += bin.value.EstimateSize();
 }