private void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get(1)] = Value.Get(55);
            inputMap[Value.Get(2)] = Value.Get(33);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            console.Info("Record: " + record);

            // Pop value from map and also return new size of map.
            record = client.Operate(args.writePolicy, key, MapOperation.RemoveByKey(binName, Value.Get(1), MapReturnType.VALUE), MapOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each map operation on the same map bin.
            // In this case, there are two map operations (pop and size), so there
            // should be two results.
            IList results = record.GetList(binName);

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
        /// <summary>
        /// Value list range example.
        /// </summary>
        private void RunListRangeExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            List <Value> l1 = new List <Value>();

            l1.Add(MillisSinceEpoch(new DateTime(2018, 1, 1)));
            l1.Add(Value.Get(1));

            List <Value> l2 = new List <Value>();

            l2.Add(MillisSinceEpoch(new DateTime(2018, 1, 2)));
            l2.Add(Value.Get(2));

            List <Value> l3 = new List <Value>();

            l3.Add(MillisSinceEpoch(new DateTime(2018, 2, 1)));
            l3.Add(Value.Get(3));

            List <Value> l4 = new List <Value>();

            l4.Add(MillisSinceEpoch(new DateTime(2018, 2, 2)));
            l4.Add(Value.Get(4));

            List <Value> l5 = new List <Value>();

            l5.Add(MillisSinceEpoch(new DateTime(2018, 2, 5)));
            l5.Add(Value.Get(5));

            IDictionary inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("Charlie")] = Value.Get(l1);
            inputMap[Value.Get("Jim")]     = Value.Get(l2);
            inputMap[Value.Get("John")]    = Value.Get(l3);
            inputMap[Value.Get("Harry")]   = Value.Get(l4);
            inputMap[Value.Get("Bill")]    = Value.Get(l5);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key,
                                           MapOperation.PutItems(MapPolicy.Default, binName, inputMap)
                                           );

            console.Info("Record: " + record);

            List <Value> end = new List <Value>();

            end.Add(MillisSinceEpoch(new DateTime(2018, 2, 2)));
            end.Add(Value.AsNull);

            // Delete values < end.
            record = client.Operate(args.writePolicy, key,
                                    MapOperation.RemoveByValueRange(binName, null, Value.Get(end), MapReturnType.COUNT)
                                    );

            console.Info("Record: " + record);
        }
        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "listkey");
            string binName = args.GetBinName("listbin");

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

            IList inputList = new List <Value>();

            inputList.Add(Value.Get(55));
            inputList.Add(Value.Get(77));

            // Write values to empty list.
            Record record = client.Operate(args.writePolicy, key, ListOperation.AppendItems(binName, inputList));

            console.Info("Record: " + record);

            // Pop value from end of list and also return new size of list.
            record = client.Operate(args.writePolicy, key, ListOperation.Pop(binName, -1), ListOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each list operation on the same list bin.
            // In this case, there are two list operations (pop and size), so there
            // should be two results.
            IList list = record.GetList(binName);

            foreach (object value in list)
            {
                console.Info("Received: " + value);
            }
        }
Exemple #4
0
        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 long IncrementSingle(string counterName, long by)
        {
            Key recordKey = new Key(NAMESPACE, SINGLE_SET, counterName);

            Bin incrementCounter = new Bin(SINGLE_COUNTER_BIN, by);

            Record record = asClient.Operate(null, recordKey, Operation.Add(incrementCounter), Operation.Get(SINGLE_COUNTER_BIN));

            return(record.GetLong(SINGLE_COUNTER_BIN));
        }
Exemple #6
0
        /// <summary>
        /// Add value to list.  Fail if value's key exists and list is configured for unique keys.
        /// If value is a map, the key is identified by "key" entry.  Otherwise, the value is the key.
        /// If large list does not exist, create it.
        /// </summary>
        /// <param name="value">value to add</param>

        public void Add(Value value)
        {
            Key subKey = MakeSubKey(value);

            client.Put(this.policy, subKey, new Bin(ListElementBinName, value));

            // add the digest of the subKey to the CDT List in the Customer record
            Value digest = Value.Get(subKey.digest);

            client.Operate(this.policy, this.key, ListOperation.Append(this.binNameString, digest));
        }
Exemple #7
0
        /// <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));
        }
Exemple #8
0
        /// <summary>
        /// Simple example of bit functionality.
        /// </summary>
        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "bitkey");
            string binName = args.GetBinName("bitbin");

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

            byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };

            client.Put(args.writePolicy, key, new Bin(binName, bytes));

            // Set last 3 bits of bitmap to true.
            Record record = client.Operate(args.writePolicy, key,
                                           BitOperation.Set(BitPolicy.Default, binName, -3, 3, new byte[] { 0xE0 }),
                                           Operation.Get(binName)
                                           );

            IList list = record.GetList(binName);

            byte[] val = (byte[])list[1];

            foreach (byte b in val)
            {
                console.Info(Convert.ToString(b));
            }
        }
        public void RunNestedListCreateExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey3");
            string binName = args.GetBinName("mapbin");

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

            IList <Value> l1 = new List <Value>();

            l1.Add(Value.Get(7));
            l1.Add(Value.Get(9));
            l1.Add(Value.Get(5));

            IDictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("key1")] = Value.Get(l1);

            // Create maps.
            client.Put(args.writePolicy, key, new Bin(binName, inputMap));

            // Create ordered list at map's "key2" only if list does not exist.
            // Append 2,1 to ordered list.
            CTX    ctx    = CTX.MapKey(Value.Get("key2"));
            Record record = client.Operate(args.writePolicy, key,
                                           ListOperation.Create(binName, ListOrder.ORDERED, false, ctx),
                                           ListOperation.Append(binName, Value.Get(2), ctx),
                                           ListOperation.Append(binName, Value.Get(1), ctx),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
Exemple #10
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 RunScoreExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")]     = Value.Get(98);
            inputMap[Value.Get("John")]    = Value.Get(76);
            inputMap[Value.Get("Harry")]   = Value.Get(82);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key,
                                           MapOperation.PutItems(MapPolicy.Default, binName, inputMap)
                                           );

            console.Info("Record: " + record);

            // Increment some user scores.
            record = client.Operate(args.writePolicy, key,
                                    MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)),
                                    MapOperation.Increment(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(-4))
                                    );

            console.Info("Record: " + record);

            // Get top two scores.
            record = client.Operate(args.writePolicy, key,
                                    MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY_VALUE)
                                    );

            // There should be one result for each map operation on the same map bin.
            // In this case, there are two map operations (pop and size), so there
            // should be two results.
            IList results = record.GetList(binName);

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
Exemple #12
0
        public void CDTListOperations()
        {
            Key   key       = new Key(NS, SET, "CDT-list-test-key");
            IList inputList = new List <Value>();

            inputList.Add(Value.Get(55));
            inputList.Add(Value.Get(77));
            for (int x = 0; x < 100; x++)
            {
                client.Operate(null, key, ListOperation.Insert("integer-list", 0, Value.Get(x)));
            }
            Record record = client.Operate(null, key, ListOperation.Size("integer-list"));

            Assert.AreEqual(100, record.GetInt("integer-list"));
            record = client.Operate(null, key, ListOperation.AppendItems("integer-list", inputList));
            record = client.Operate(null, key, ListOperation.Size("integer-list"));
            Assert.AreEqual(102, record.GetInt("integer-list"));
        }
Exemple #13
0
        } //updateUser

        private void updateUserUsingOperate(AerospikeClient client, Key userKey, WritePolicy policy, long ts)
        {
            // TODO: Initiate operate passing in policy, user record key,
            // .Add operation incrementing tweet count, .Put operation updating timestamp
            // and .Get operation to read the user record.
            // Exercise K6
            Record record = client.Operate(policy, userKey, Operation.Add(new Bin("tweetcount", 1)), Operation.Put(new Bin("lasttweeted", ts)), Operation.Get());

            // TODO: Output the most recent tweetcount
            // Exercise K6
            Console.WriteLine("INFO: The tweet count now is: " + record.GetValue("tweetcount"));
        } //updateUserUsingOperate
Exemple #14
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.");
            }
        }
Exemple #15
0
        private static void MultiOps(AerospikeClient client,
                                     WritePolicy writePolicy, Key key)
        {
            Console.WriteLine("Multiops");
            var bin1 = new Bin("optintbin", 7);
            var bin2 = new Bin("optstringbin", "string value");

            client.Put(writePolicy, key, bin1, bin2);
            var bin3   = new Bin(bin1.name, 4);
            var bin4   = new Bin(bin2.name, "new string");
            var record = client.Operate(writePolicy, key, Operation.Add(bin3),
                                        Operation.Put(bin4), Operation.Get());

            Console.WriteLine("Record: " + record);
        }
Exemple #16
0
        /// <summary>
        /// Operate on a list of lists.
        /// </summary>
        private void RunNestedExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "listkey2");
            string binName = args.GetBinName("listbin");

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

            IList <Value> l1 = new List <Value>();

            l1.Add(Value.Get(7));
            l1.Add(Value.Get(9));
            l1.Add(Value.Get(5));

            IList <Value> l2 = new List <Value>();

            l2.Add(Value.Get(1));
            l2.Add(Value.Get(2));
            l2.Add(Value.Get(3));

            IList <Value> l3 = new List <Value>();

            l3.Add(Value.Get(6));
            l3.Add(Value.Get(5));
            l3.Add(Value.Get(4));
            l3.Add(Value.Get(1));

            IList <Value> inputList = new List <Value>();

            inputList.Add(Value.Get(l1));
            inputList.Add(Value.Get(l2));
            inputList.Add(Value.Get(l3));

            // Create list.
            client.Put(args.writePolicy, key, new Bin(binName, inputList));

            // Append value to last list and retrieve all lists.
            Record record = client.Operate(args.writePolicy, key,
                                           ListOperation.Append(binName, Value.Get(11), CTX.ListIndex(-1)),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
        public void RunNestedMapCreateExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey2");
            string binName = args.GetBinName("mapbin");

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

            IDictionary <Value, Value> m1 = new Dictionary <Value, Value>();

            m1[Value.Get("key21")] = Value.Get(7);
            m1[Value.Get("key22")] = Value.Get(6);

            IDictionary <Value, Value> m2 = new Dictionary <Value, Value>();

            m2[Value.Get("a")] = Value.Get(3);
            m2[Value.Get("c")] = Value.Get(5);

            IDictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("key1")] = Value.Get(m1);
            inputMap[Value.Get("key2")] = Value.Get(m2);

            // Create maps.
            client.Put(args.writePolicy, key, new Bin(binName, inputMap));

            // Create key ordered map at "key2" only if map does not exist.
            // Set map value to 4 for map key "key21" inside of map key "key2".
            CTX    ctx    = CTX.MapKey(Value.Get("key2"));
            Record record = client.Operate(args.writePolicy, key,
                                           MapOperation.Create(binName, MapOrder.KEY_VALUE_ORDERED, ctx),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("b"), Value.Get(4), ctx),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
Exemple #18
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();
        }
        /// <summary>
        /// Operate on a map of maps.
        /// </summary>
        private void RunNestedExample(AerospikeClient client, Arguments args)
        {
            Key    key     = new Key(args.ns, args.set, "mapkey2");
            string binName = args.GetBinName("mapbin");

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

            IDictionary <Value, Value> m1 = new Dictionary <Value, Value>();

            m1[Value.Get("key11")] = Value.Get(9);
            m1[Value.Get("key12")] = Value.Get(4);

            IDictionary <Value, Value> m2 = new Dictionary <Value, Value>();

            m2[Value.Get("key21")] = Value.Get(3);
            m2[Value.Get("key22")] = Value.Get(5);

            IDictionary <Value, Value> inputMap = new Dictionary <Value, Value>();

            inputMap[Value.Get("key1")] = Value.Get(m1);
            inputMap[Value.Get("key2")] = Value.Get(m2);

            // Create maps.
            client.Put(args.writePolicy, key, new Bin(binName, inputMap));

            // Set map value to 11 for map key "key21" inside of map key "key2"
            // and retrieve all maps.
            Record record = client.Operate(args.writePolicy, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key21"), Value.Get(11), CTX.MapKey(Value.Get("key2"))),
                                           Operation.Get(binName)
                                           );

            record = client.Get(args.policy, key);
            console.Info("Record: " + record);
        }
Exemple #20
0
        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());
        }
Exemple #21
0
        } //updateUser

        private void updateUserUsingOperate(AerospikeClient client, Key userKey, WritePolicy policy, long ts)
        {
            Record record = client.Operate(policy, userKey, Operation.Add(new Bin("tweetcount", 1)), Operation.Put(new Bin("lasttweeted", ts)), Operation.Get());

            Console.WriteLine("INFO: The tweet count now is: " + record.GetValue("tweetcount"));
        } //updateUserUsingOperate
        /// <summary>
        /// Example functions not in use
        /// </summary>
        private void deleteTweets()
        {
            RecordSet rs = null;

            try
            {
                // Get username
                string username;
                Console.WriteLine("\nEnter username:"******"test", "users", username);
                    Record userRecord = client.Get(null, userKey);
                    if (userRecord != null)
                    {
                        WritePolicy wPolicy = new WritePolicy();
                        wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

                        string[]  bins = { "tweet" };
                        Statement stmt = new Statement();
                        stmt.SetNamespace("test");
                        stmt.SetSetName("tweets");
                        stmt.SetIndexName("username_index");
                        stmt.SetBinNames(bins);
                        stmt.SetFilters(Filter.Equal("username", username));

                        Console.WriteLine("\nDeleting " + username + "'s tweet(s):\n");

                        rs = client.Query(null, stmt);
                        while (rs.Next())
                        {
                            Record r = rs.Record;
                            Console.WriteLine(r.GetValue("tweet"));
                            client.Delete(null, rs.Key);
                        }
                        //Update tweetcount and timestamp to reflect this
                        client.Operate(wPolicy, userKey, Operation.Put(new Bin("tweetcount", 0)), Operation.Put(new Bin("lasttweeted", 0)));
                        rs.Close();
                    }
                    else
                    {
                        Console.WriteLine("ERROR: User record not found!");
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        }