Example #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())));
        }
        protected internal static Operation CreateRangeOperation(int command, Operation.Type type, string binName, Value begin, Value end, int returnType)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);

            if (begin == null)
            {
                begin = Value.AsNull;
            }

            if (end == null)
            {
                packer.PackArrayBegin(2);
                packer.PackNumber(returnType);
                begin.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                packer.PackNumber(returnType);
                begin.Pack(packer);
                end.Pack(packer);
            }
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Example #4
0
        internal static void Init(Packer packer, CTX[] ctx, int command, int count)
        {
            if (ctx != null && ctx.Length > 0)
            {
                packer.PackArrayBegin(3);
                packer.PackNumber(0xff);
                packer.PackArrayBegin(ctx.Length * 2);

                foreach (CTX c in ctx)
                {
                    packer.PackNumber(c.id);
                    c.value.Pack(packer);
                }
                packer.PackArrayBegin(count + 1);
                packer.PackNumber(command);
            }
            else
            {
                packer.PackRawShort(command);

                if (count > 0)
                {
                    packer.PackArrayBegin(count);
                }
            }
        }
        /// <summary>
        /// Create default list append operation.
        /// Server appends value to end of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation Append(string binName, Value value)
        {
            Packer packer = new Packer();

            packer.PackRawShort(APPEND);
            packer.PackArrayBegin(1);
            value.Pack(packer);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
 /// <summary>
 /// Create list append operation.
 /// Server appends value to end of list bin.
 /// Server returns list size.
 /// </summary>
 public static Operation Append(string binName, Value value)
 {
     Packer packer = new Packer();
     packer.PackRawShort(APPEND);
     packer.PackArrayBegin(1);
     value.Pack(packer);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
Example #7
0
        /// <summary>
        /// Create list clear operation.
        /// Server removes all items in list bin.
        /// Server does not return a result by default.
        /// </summary>
        public static Operation Clear(string binName)
        {
            Packer packer = new Packer();

            packer.PackRawShort(CLEAR);
            //packer.PackArrayBegin(0);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
Example #8
0
        /// <summary>
        /// Create list size operation.
        /// Server returns size of list.
        /// </summary>
        public static Operation Size(string binName)
        {
            Packer packer = new Packer();

            packer.PackRawShort(SIZE);
            //packer.PackArrayBegin(0);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes)));
        }
Example #9
0
        protected internal static Operation SetMapPolicy(string binName, int attributes)
        {
            Packer packer = new Packer();

            packer.PackRawShort(SET_TYPE);
            packer.PackArrayBegin(1);
            packer.PackNumber(attributes);
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create default list append items operation.
        /// Server appends each input list item to end of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation AppendItems(string binName, IList list)
        {
            Packer packer = new Packer();

            packer.PackRawShort(APPEND_ITEMS);
            packer.PackArrayBegin(1);
            packer.PackList(list);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, int v1, Value v2)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(2);
            packer.PackNumber(v1);
            v2.Pack(packer);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create default list insert items operation.
        /// Server inserts each input list item starting at specified index of list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation InsertItems(string binName, int index, IList list)
        {
            Packer packer = new Packer();

            packer.PackRawShort(INSERT_ITEMS);
            packer.PackArrayBegin(2);
            packer.PackNumber(index);
            packer.PackList(list);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Example #13
0
        /// <summary>
        /// Create list increment operation.
        /// Server increments list[index] by 1.
        /// Server returns list[index] after incrementing.
        /// </summary>
        public static Operation Increment(string binName, int index)
        {
            Packer packer = new Packer();

            packer.PackRawShort(INCREMENT);
            packer.PackArrayBegin(1);
            packer.PackNumber(index);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
Example #14
0
        /// <summary>
        /// Create list get range operation.
        /// Server returns items starting at index to the end of list.
        /// </summary>
        public static Operation GetRange(string binName, int index)
        {
            Packer packer = new Packer();

            packer.PackRawShort(GET_RANGE);
            packer.PackArrayBegin(1);
            packer.PackNumber(index);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes)));
        }
Example #15
0
        protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, int index, MapReturnType returnType)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(2);
            packer.PackNumber((int)returnType);
            packer.PackNumber(index);
            return(new Operation(type, binName, Value.Get(packer.ToByteArray())));
        }
Example #16
0
 protected internal static Operation CreateOperation(int command, int attributes, string binName, Value value1, Value value2)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     packer.PackArrayBegin(3);
     value1.Pack(packer);
     value2.Pack(packer);
     packer.PackNumber(attributes);
     return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
 }
Example #17
0
        /// <summary>
        /// Create list trim operation.
        /// Server removes items in list bin that do not fall into range specified by index
        /// and count range.  If the range is out of bounds, then all items will be removed.
        /// Server returns list size after trim.
        /// </summary>
        public static Operation Trim(string binName, int index, int count)
        {
            Packer packer = new Packer();

            packer.PackRawShort(TRIM);
            packer.PackArrayBegin(2);
            packer.PackNumber(index);
            packer.PackNumber(count);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
        /// <summary>
        /// Create list append items operation with policy.
        /// Server appends each input list item to list bin.
        /// Server returns list size.
        /// </summary>
        public static Operation AppendItems(ListPolicy policy, string binName, IList list)
        {
            Packer packer = new Packer();

            packer.PackRawShort(APPEND_ITEMS);
            packer.PackArrayBegin(3);
            packer.PackList(list);
            packer.PackNumber(policy.attributes);
            packer.PackNumber(policy.flags);
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Example #19
0
        protected internal static Operation CreateOperation(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);
            packer.PackArrayBegin(3);
            value1.Pack(packer);
            value2.Pack(packer);
            packer.PackNumber(attributes);
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
Example #20
0
        /// <summary>
        /// Create list set operation.
        /// Server sets item value at specified index in list bin.
        /// Server does not return a result by default.
        /// </summary>
        public static Operation Set(string binName, int index, Value value)
        {
            Packer packer = new Packer();

            packer.PackRawShort(SET);
            packer.PackArrayBegin(2);
            packer.PackNumber(index);
            value.Pack(packer);
            byte[] bytes = packer.ToByteArray();
            return(new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes)));
        }
        /// <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())));
        }
Example #22
0
        protected internal static Operation CreatePut(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();

            packer.PackRawShort(command);

            if (command == MapBase.REPLACE)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(2);
                value1.Pack(packer);
                value2.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                value1.Pack(packer);
                value2.Pack(packer);
                packer.PackNumber(attributes);
            }
            return(new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
 /// <summary>
 /// Create list insert items operation.
 /// Server inserts each input list item starting at specified index of list bin. 
 /// Server returns list size.
 /// </summary>
 public static Operation InsertItems(string binName, int index, IList list)
 {
     Packer packer = new Packer();
     packer.PackRawShort(INSERT_ITEMS);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackList(list);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 /// <summary>
 /// Create list remove range operation.
 /// Server removes items starting at specified index to the end of list.
 /// Server returns number of items removed.
 /// </summary>
 public static Operation RemoveRange(string binName, int index)
 {
     Packer packer = new Packer();
     packer.PackRawShort(REMOVE_RANGE);
     packer.PackArrayBegin(1);
     packer.PackNumber(index);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
 /// <summary>
 /// Create list append items operation.
 /// Server appends each input list item to end of list bin.
 /// Server returns list size.
 /// </summary>
 public static Operation AppendItems(string binName, IList list)
 {
     Packer packer = new Packer();
     packer.PackRawShort(APPEND_ITEMS);
     packer.PackArrayBegin(1);
     packer.PackList(list);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
Example #26
0
        protected internal static Operation CreateRangeOperation(int command, Operation.Type type, string binName, Value begin, Value end, MapReturnType returnType)
        {
            Packer packer = new Packer();
            packer.PackRawShort(command);

            if (begin == null)
            {
                begin = Value.AsNull;
            }

            if (end == null)
            {
                packer.PackArrayBegin(2);
                packer.PackNumber((int)returnType);
                begin.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                packer.PackNumber((int)returnType);
                begin.Pack(packer);
                end.Pack(packer);
            }
            return new Operation(type, binName, Value.Get(packer.ToByteArray()));
        }
 /// <summary>
 /// Create list set operation.
 /// Server sets item value at specified index in list bin.
 /// Server does not return a result by default.
 /// </summary>
 public static Operation Set(string binName, int index, Value value)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SET);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     value.Pack(packer);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
        /// <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 list size operation.
 /// Server returns size of list.
 /// </summary>
 public static Operation Size(string binName)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SIZE);
     //packer.PackArrayBegin(0);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes));
 }
Example #30
0
        protected internal static Operation CreatePut(int command, int attributes, string binName, Value value1, Value value2)
        {
            Packer packer = new Packer();
            packer.PackRawShort(command);

            if (command == MapBase.REPLACE)
            {
                // Replace doesn't allow map attributes because it does not create on non-existing key.
                packer.PackArrayBegin(2);
                value1.Pack(packer);
                value2.Pack(packer);
            }
            else
            {
                packer.PackArrayBegin(3);
                value1.Pack(packer);
                value2.Pack(packer);
                packer.PackNumber(attributes);
            }
            return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
        }
Example #31
0
 protected internal static Operation CreateOperation(int command, Operation.Type type, string binName, Value value, MapReturnType returnType)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     packer.PackArrayBegin(2);
     packer.PackNumber((int)returnType);
     value.Pack(packer);
     return new Operation(type, binName, Value.Get(packer.ToByteArray()));
 }
Example #32
0
 protected internal static Operation CreateOperation(int command, Operation.Type type, string binName)
 {
     Packer packer = new Packer();
     packer.PackRawShort(command);
     return new Operation(type, binName, Value.Get(packer.ToByteArray()));
 }
 /// <summary>
 /// Create list get range operation.
 /// Server returns "count" items starting at specified index in list bin.
 /// </summary>
 public static Operation GetRange(string binName, int index, int count)
 {
     Packer packer = new Packer();
     packer.PackRawShort(GET_RANGE);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackNumber(count);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_READ, binName, Value.Get(bytes));
 }
 /// <summary>
 /// Create list trim operation.
 /// Server removes "count" items in list bin that do not fall into range specified
 /// by index and count range.  If the range is out of bounds, then all items will be removed.
 /// Server returns list size after trim.
 /// </summary>
 public static Operation Trim(string binName, int index, int count)
 {
     Packer packer = new Packer();
     packer.PackRawShort(TRIM);
     packer.PackArrayBegin(2);
     packer.PackNumber(index);
     packer.PackNumber(count);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }
Example #35
0
 protected internal static Operation SetMapPolicy(string binName, int attributes)
 {
     Packer packer = new Packer();
     packer.PackRawShort(SET_TYPE);
     packer.PackArrayBegin(1);
     packer.PackNumber(attributes);
     return new Operation(Operation.Type.MAP_MODIFY, binName, Value.Get(packer.ToByteArray()));
 }
 /// <summary>
 /// Create list clear operation.
 /// Server removes all items in list bin.
 /// Server does not return a result by default.
 /// </summary>
 public static Operation Clear(string binName)
 {
     Packer packer = new Packer();
     packer.PackRawShort(CLEAR);
     //packer.PackArrayBegin(0);
     byte[] bytes = packer.ToByteArray();
     return new Operation(Operation.Type.CDT_MODIFY, binName, Value.Get(bytes));
 }