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);
        }
        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);
        }
        /// <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);
        }
Example #4
0
        public void OperateNestedListMap()
        {
            Key key = new Key(args.ns, args.set, "oplkey19");

            client.Delete(null, key);

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

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

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

            l12.Add(Value.Get(13));

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

            l1.Add(Value.Get(l11));
            l1.Add(Value.Get(l12));

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

            l21.Add(Value.Get(9));

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

            l22.Add(Value.Get(2));
            l22.Add(Value.Get(4));

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

            l23.Add(Value.Get(6));
            l23.Add(Value.Get(1));
            l23.Add(Value.Get(9));

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

            l2.Add(Value.Get(l21));
            l2.Add(Value.Get(l22));
            l2.Add(Value.Get(l23));

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

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

            // Create list.
            client.Put(null, key, new Bin(binName, inputMap));

            // Append value to last list and retrieve map.
            Record record = client.Operate(null, key,
                                           ListOperation.Append(binName, Value.Get(11), CTX.MapKey(Value.Get("key2")), CTX.ListRank(0)),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long count = (long)results[i++];

            Assert.AreEqual(3, count);

            IDictionary map = (IDictionary)results[i++];

            Assert.AreEqual(2, map.Count);

            // Test affected nested list.
            IList list = (IList)map["key2"];

            Assert.AreEqual(3, list.Count);

            list = (IList)list[1];
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(2, (long)(long?)list[0]);
            Assert.AreEqual(4, (long)(long?)list[1]);
            Assert.AreEqual(11, (long)(long?)list[2]);
        }
        public void OperateDoubleNestedMap()
        {
            Key key = new Key(args.ns, args.set, "opmkey19");

            client.Delete(null, key);

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

            m11[Value.Get("key111")] = Value.Get(1);

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

            m12[Value.Get("key121")] = Value.Get(5);

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

            m1[Value.Get("key11")] = Value.Get(m11);
            m1[Value.Get("key12")] = Value.Get(m12);

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

            m21[Value.Get("key211")] = Value.Get(7);

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

            m2[Value.Get("key21")] = Value.Get(m21);

            Dictionary <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(null, 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(null, key,
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key121"), Value.Get(11), CTX.MapKey(Value.Get("key1")), CTX.MapRank(-1)),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int   i       = 0;

            long count = (long)results[i++];

            Assert.AreEqual(1, count);

            IDictionary map = (IDictionary)results[i++];

            Assert.AreEqual(2, map.Count);

            map = (IDictionary)map["key1"];
            Assert.AreEqual(2, map.Count);

            map = (IDictionary)map["key12"];
            Assert.AreEqual(1, map.Count);

            long v = (long)map["key121"];

            Assert.AreEqual(11, v);
        }
        public void OperateMapCreateContext()
        {
            Key key = new Key(args.ns, args.set, "opmkey20");

            client.Delete(null, 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(null, 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(null, key,
                                           MapOperation.Create(binName, MapOrder.KEY_ORDERED, CTX.MapKey(Value.Get("key3"))),
                                           MapOperation.Put(MapPolicy.Default, binName, Value.Get("key31"), Value.Get(99), CTX.MapKey(Value.Get("key3"))),
                                           //MapOperation.Put(MapPolicy.Default, binName, Value.Get("key31"), Value.Get(99), CTX.MapKeyCreate(Value.Get("key3"), MapOrder.KEY_ORDERED)),
                                           Operation.Get(binName)
                                           );

            AssertRecordFound(key, record);
            //Console.WriteLine("Record: " + record);

            IList results = record.GetList(binName);
            int   i       = 1;

            long count = (long)results[i++];

            Assert.AreEqual(1, count);

            IDictionary map = (IDictionary)results[i++];

            Assert.AreEqual(3, map.Count);

            map = (IDictionary)map["key3"];
            Assert.AreEqual(1, map.Count);

            long v = (long)map["key31"];

            Assert.AreEqual(99, v);
        }