Example #1
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);
            }
        }
        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);
        }
Example #3
0
        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("");
        }
Example #4
0
        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();
        }
Example #5
0
        public void updateRecords()
        {
            Console.WriteLine("\n********** Updating counter **********\n");
            WritePolicy wPolicy = new WritePolicy();

            wPolicy.recordExistsAction = RecordExistsAction.UPDATE;
            wPolicy.expiration         = 1296000;
            for (int i = 0; i < 100; i++)
            {
                string myKey = "key" + i;
                Key    key   = new Key("test", "demo", myKey);
                Bin    bin1  = new Bin(string.Empty, 1);
                client.Add(wPolicy, key, bin1);
            }
        }