Exemple #1
0
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the flags used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map)
        {
            Packer packer = new Packer();

            if (policy.flags != 0)
            {
                packer.PackRawShort(PUT_ITEMS);
                packer.PackArrayBegin(3);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
                packer.PackNumber(policy.flags);
            }
            else
            {
                packer.PackRawShort(policy.itemsCommand);

                if (policy.itemsCommand == REPLACE_ITEMS)
                {
                    // Replace doesn't allow map attributes because it does not create on non-existing key.
                    packer.PackArrayBegin(1);
                    packer.PackMap(map);
                }
                else
                {
                    packer.PackArrayBegin(2);
                    packer.PackMap(map);
                    packer.PackNumber(policy.attributes);
                }
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the flags used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map, params CTX[] ctx)
        {
            Packer packer = new Packer();

            if (policy.flags != 0)
            {
                CDT.Init(packer, ctx, PUT_ITEMS, 3);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
                packer.PackNumber(policy.flags);
            }
            else
            {
                if (policy.itemsCommand == REPLACE_ITEMS)
                {
                    // Replace doesn't allow map attributes because it does not create on non-existing key.
                    CDT.Init(packer, ctx, policy.itemsCommand, 1);
                    packer.PackMap(map);
                }
                else
                {
                    CDT.Init(packer, ctx, policy.itemsCommand, 2);
                    packer.PackMap(map);
                    packer.PackNumber(policy.attributes);
                }
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create map put operation.
        /// Server writes key/value item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the mode used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
        /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
        /// </para>
        /// </summary>
        public static Operation Put(MapPolicy policy, string binName, Value key, Value value)
        {
            Packer packer = new Packer();

            packer.PackRawShort(policy.itemCommand);

            if (policy.itemCommand == REPLACE)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(2);
                key.Pack(packer);
                value.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                key.Pack(packer);
                value.Pack(packer);
                packer.PackNumber(policy.attributes);
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Exemple #4
0
        /// <summary>
        /// Create map put operation.
        /// Server writes key/value item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the flags used when writing items to the map.
        /// See policy <see cref="Aerospike.Client.MapPolicy"/>.
        /// </para>
        /// </summary>
        public static Operation Put(MapPolicy policy, string binName, Value key, Value value, params CTX[] ctx)
        {
            Packer packer = new Packer();

            if (policy.flags != 0)
            {
                PackUtil.Init(packer, ctx);
                packer.PackArrayBegin(5);
                packer.PackNumber(MapOperation.PUT);
                key.Pack(packer);
                value.Pack(packer);
                packer.PackNumber(policy.attributes);
                packer.PackNumber(policy.flags);
            }
            else
            {
                if (policy.itemCommand == REPLACE)
                {
                    // Replace doesn't allow map attributes because it does not create on non-existing key.
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(3);
                    packer.PackNumber(policy.itemCommand);
                    key.Pack(packer);
                    value.Pack(packer);
                }
                else
                {
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(4);
                    packer.PackNumber(policy.itemCommand);
                    key.Pack(packer);
                    value.Pack(packer);
                    packer.PackNumber(policy.attributes);
                }
            }
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes)));
        }
 /// <summary>
 /// Create map decrement operation.
 /// Server decrements values by decr for all items identified by key and returns final result.
 /// Valid only for numbers. 
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode 
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Decrement(MapPolicy policy, string binName, Value key, Value decr)
 {
     return MapBase.CreateOperation(MapBase.DECREMENT, policy.attributes, binName, key, decr);
 }
 /// <summary>
 /// Create set map policy operation.
 /// Server sets map policy attributes.  Server returns null.
 /// <para>
 /// The required map policy attributes can be changed after the map is created.
 /// </para>
 /// </summary>
 public static Operation SetMapPolicy(MapPolicy policy, string binName)
 {
     return MapBase.SetMapPolicy(binName, policy.attributes);
 }
        /// <summary>
        /// Create map put items operation
        /// Server writes each map item to map bin and returns map size.
        /// <para>
        /// The required map policy dictates the type of map to create when it does not exist.
        /// The map policy also specifies the mode used when writing items to the map.
        /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode 
        /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
        /// </para>
        /// </summary>
        public static Operation PutItems(MapPolicy policy, string binName, IDictionary map)
        {
            Packer packer = new Packer();
            packer.PackRawShort(policy.itemsCommand);

            if (policy.itemsCommand == MapBase.REPLACE_ITEMS)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(1);
                packer.PackMap(map);
            }
            else
            {
                packer.PackArrayBegin(2);
                packer.PackMap(map);
                packer.PackNumber(policy.attributes);
            }
            return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
        }
 /// <summary>
 /// Create map put operation.
 /// Server writes key/value item to map bin and returns map size.
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode 
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Put(MapPolicy policy, string binName, Value key, Value value)
 {
     return MapBase.CreatePut(policy.itemCommand, policy.attributes, binName, key, value);
 }
 /// <summary>
 /// Create set map policy operation.
 /// Server sets map policy attributes.  Server returns null.
 /// <para>
 /// The required map policy attributes can be changed after the map is created.
 /// </para>
 /// </summary>
 public static Operation SetMapPolicy(MapPolicy policy, string binName)
 {
     return(MapBase.SetMapPolicy(binName, policy.attributes));
 }
 /// <summary>
 /// Create map decrement operation.
 /// Server decrements values by decr for all items identified by key and returns final result.
 /// Valid only for numbers.
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Decrement(MapPolicy policy, string binName, Value key, Value decr)
 {
     return(MapBase.CreateOperation(MapBase.DECREMENT, policy.attributes, binName, key, decr));
 }
        public void OperateMapScore()
        {
            // Test score.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey10");
            client.Delete(null, key);

            MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE);

            Dictionary<Value, Value> inputMap = new Dictionary<Value, Value>();
            inputMap[Value.Get("weiling")] = Value.Get(0);
            inputMap[Value.Get("briann")] = Value.Get(0);
            inputMap[Value.Get("brianb")] = Value.Get(0);
            inputMap[Value.Get("meher")] = Value.Get(0);

            // Create map.
            Record record = client.Operate(null, key, MapOperation.PutItems(mapPolicy, binName, inputMap));

            AssertRecordFound(key, record);

            // Change scores
            record = client.Operate(null, key,
                MapOperation.Increment(mapPolicy, binName, Value.Get("weiling"), Value.Get(10)),
                MapOperation.Increment(mapPolicy, binName, Value.Get("briann"), Value.Get(20)),
                MapOperation.Increment(mapPolicy, binName, Value.Get("brianb"), Value.Get(1)),
                MapOperation.Increment(mapPolicy, binName, Value.Get("meher"), Value.Get(20))
                );

            AssertRecordFound(key, record);

            // Query top 3 scores
            record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY));

            AssertRecordFound(key, record);

            // Remove people with score 10 and display top 3 again
            record = client.Operate(null, key,
                MapOperation.RemoveByValue(binName, Value.Get(10), MapReturnType.KEY),
                MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY)
                );

            AssertRecordFound(key, record);

            IList results = record.GetList(binName);
            int i = 0;
            IList list = (IList)results[i++];
            string s = (string)list[0];
            Assert.AreEqual("weiling", s);

            list = (IList)results[i++];
            s = (string)list[0];
            Assert.AreEqual("brianb", s);
            s = (string)list[1];
            Assert.AreEqual("briann", s);
            s = (string)list[2];
            Assert.AreEqual("meher", s);
        }
        public void OperateMapPutItems()
        {
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey2");
            client.Delete(null, key);

            Dictionary<Value, Value> addMap = new Dictionary<Value, Value>();
            addMap[Value.Get(12)] = Value.Get("myval");
            addMap[Value.Get(-8734)] = Value.Get("str2");
            addMap[Value.Get(1)] = Value.Get("my default");

            Dictionary<Value, Value> putMap = new Dictionary<Value, Value>();
            putMap[Value.Get(12)] = Value.Get("myval12222");
            putMap[Value.Get(13)] = Value.Get("str13");

            Dictionary<Value, Value> updateMap = new Dictionary<Value, Value>();
            updateMap[Value.Get(13)] = Value.Get("myval2");
            updateMap[Value.Get(14)] = Value.Get("str14");

            Dictionary<Value, Value> replaceMap = new Dictionary<Value, Value>();
            replaceMap[Value.Get(12)] = Value.Get(23);
            replaceMap[Value.Get(-8734)] = Value.Get("changed");

            MapPolicy putMode = MapPolicy.Default;
            MapPolicy addMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.CREATE_ONLY);
            MapPolicy updateMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE_ONLY);

            Record record = client.Operate(null, key,
                MapOperation.PutItems(addMode, binName, addMap),
                MapOperation.PutItems(putMode, binName, putMap),
                MapOperation.PutItems(updateMode, binName, updateMap),
                MapOperation.PutItems(updateMode, binName, replaceMap),
                MapOperation.GetByKey(binName, Value.Get(1), MapReturnType.VALUE),
                MapOperation.GetByKey(binName, Value.Get(-8734), MapReturnType.VALUE),
                MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.KEY_VALUE)
                );

            AssertRecordFound(key, record);

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

            long size = (long)results[i++];
            Assert.AreEqual(3, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            string str = (string)results[i++];
            Assert.AreEqual("my default", str);

            str = (string)results[i++];
            Assert.AreEqual("changed", str);

            IList list = (IList)results[i++];
            Assert.AreEqual(2, list.Count);
        }
        public void OperateMapPut()
        {
            if (! args.ValidateMap()) {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey1");
            client.Delete(null, key);

            MapPolicy putMode = MapPolicy.Default;
            MapPolicy addMode = new MapPolicy(MapOrder.UNORDERED, MapWriteMode.CREATE_ONLY);
            MapPolicy updateMode = new MapPolicy(MapOrder.UNORDERED, MapWriteMode.UPDATE_ONLY);
            MapPolicy orderedUpdateMode = new MapPolicy(MapOrder.KEY_ORDERED, MapWriteMode.UPDATE_ONLY);

            // Calling put() multiple times performs poorly because the server makes
            // a copy of the map for each call, but we still need to test it.
            // putItems() should be used instead for best performance.
            Record record = client.Operate(null, key,
                    MapOperation.Put(putMode, binName, Value.Get(11), Value.Get(789)),
                    MapOperation.Put(putMode, binName, Value.Get(10), Value.Get(999)),
                    MapOperation.Put(addMode, binName, Value.Get(12), Value.Get(500)),
                    MapOperation.Put(addMode, binName, Value.Get(15), Value.Get(1000)),
                    // Ordered type should be ignored since map has already been created in first put().
                    MapOperation.Put(orderedUpdateMode, binName, Value.Get(10), Value.Get(1)),
                    MapOperation.Put(updateMode, binName, Value.Get(77), Value.Get(5))
                    );

            AssertRecordFound(key, record);

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

            long size = (long)results[i++];
            Assert.AreEqual(1, size);

            size = (long)results[i++];
            Assert.AreEqual(2, size);

            size = (long)results[i++];
            Assert.AreEqual(3, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            size = (long)results[i++];
            Assert.AreEqual(4, size);

            record = client.Get(null, key, binName);

            IDictionary map = record.GetMap(binName);
            Assert.AreEqual(4, map.Count);
            Assert.AreEqual(1L, map[10L]);
        }
Exemple #14
0
 public static Operation Decrement(MapPolicy policy, string binName, Value key, Value decr, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.DECREMENT, key, decr, policy.attributes, ctx);
     return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes)));
 }
 /// <summary>
 /// Create map increment operation.
 /// Server increments values by incr for all items identified by key and returns final result.
 /// Valid only for numbers.
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Increment(MapPolicy policy, string binName, Value key, Value incr)
 {
     return(CDT.CreateOperation(INCREMENT, Operation.Type.MAP_MODIFY, binName, key, incr, policy.attributes));
 }
 /// <summary>
 /// Create set map policy operation.
 /// Server sets map policy attributes.  Server returns null.
 /// <para>
 /// The required map policy attributes can be changed after the map is created.
 /// </para>
 /// </summary>
 public static Operation SetMapPolicy(MapPolicy policy, string binName, params CTX[] ctx)
 {
     return(CDT.CreateOperation(SET_TYPE, Operation.Type.MAP_MODIFY, binName, ctx, policy.attributes));
 }
 /// <summary>
 /// Create map put operation.
 /// Server writes key/value item to map bin and returns map size.
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Put(MapPolicy policy, string binName, Value key, Value value)
 {
     return(MapBase.CreatePut(policy.itemCommand, policy.attributes, binName, key, value));
 }
 /// <summary>
 /// Create map decrement operation.
 /// Server decrements values by decr for all items identified by key and returns final result.
 /// Valid only for numbers.
 /// <para>
 /// The required map policy dictates the type of map to create when it does not exist.
 /// The map policy also specifies the mode used when writing items to the map.
 /// See policy <seealso cref="Aerospike.Client.MapPolicy"/> and write mode
 /// <seealso cref="Aerospike.Client.MapWriteMode"/>.
 /// </para>
 /// </summary>
 public static Operation Decrement(MapPolicy policy, string binName, Value key, Value decr, params CTX[] ctx)
 {
     return(CDT.CreateOperation(DECREMENT, Operation.Type.MAP_MODIFY, binName, ctx, key, decr, policy.attributes));
 }
Exemple #19
0
 /// <summary>
 /// Create set map policy operation.
 /// Server sets map policy attributes.  Server returns null.
 /// <para>
 /// The required map policy attributes can be changed after the map is created.
 /// </para>
 /// </summary>
 public static Operation SetMapPolicy(MapPolicy policy, string binName, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.SET_TYPE, policy.attributes, ctx);
     return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(bytes)));
 }