class Aerospike::CDT::MapOperation

Unique key map bin operations. Create map operations used by the client operate command. The default unique key map is unordered.

All maps maintain an index and a rank. The index is the item offset from the start of the map, for both unordered and ordered maps. The rank is the sorted index of the value component. Map supports negative indexing for index and rank.

Index examples:

Index 0: First item in map. Index 4: Fifth item in map. Index -1: Last item in map. Index -3: Third to last item in map. Index 1 Count 2: Second and third items in map. Index -3 Count 3: Last three items in map. Index -5 Count 4: Range between fifth to last item to second to last item inclusive.

Rank examples:

Rank 0: Item with lowest value rank in map. Rank 4: Fifth lowest ranked item in map. Rank -1: Item with highest ranked value in map. Rank -3: Item with third highest ranked value in map. Rank 1 Count 2: Second and third lowest ranked items in map. Rank -3 Count 3: Top three ranked items in map.

Nested CDT operations are supported by optional CTX context arguments. Examples:

bin = {key1:{key11:9,key12:4}, key2:{key21:3,key22:5}} Set map value to 11 for map key “key21” inside of map key “key2”. MapOperation.put(“bin”, “key21”, 11, ctx: [Context.map_key(“key2”)]) bin result = {key1:{key11:9,key12:4},key2:{key21:11,key22:5}}

bin : {key1:{key11:{key111:1},key12:{key121:5}}, key2:{key21:{“key211”:7}}} Set map value to 11 in map key “key121” for highest ranked map (“key12”) inside of map key “key1”. MapOperation.put(“bin”, “key121”, 11, ctx: [Context.map_key(“key1”), Context.map_rank(-1)]) bin result = {key1:{key11:{key111:1},key12:{key121:11}}, key2:{key21:{“key211”:7}}}

Constants

ADD
ADD_ITEMS
CLEAR
DECREMENT
GET_BY_INDEX
GET_BY_INDEX_RANGE
GET_BY_KEY
GET_BY_KEY_INTERVAL
GET_BY_KEY_LIST
GET_BY_KEY_REL_INDEX_RANGE
GET_BY_RANK
GET_BY_RANK_RANGE
GET_BY_VALUE
GET_BY_VALUE_INTERVAL
GET_BY_VALUE_LIST
GET_BY_VALUE_REL_RANK_RANGE
INCREMENT
PUT
PUT_ITEMS
REMOVE_BY_INDEX
REMOVE_BY_INDEX_RANGE
REMOVE_BY_KEY
REMOVE_BY_KEY_INTERVAL
REMOVE_BY_KEY_LIST
REMOVE_BY_KEY_REL_INDEX_RANGE
REMOVE_BY_RANK
REMOVE_BY_RANK_RANGE
REMOVE_BY_VALUE
REMOVE_BY_VALUE_INTERVAL
REMOVE_BY_VALUE_LIST
REMOVE_BY_VALUE_REL_RANK_RANGE
REPLACE
REPLACE_ITEMS
SET_TYPE
SIZE

Attributes

arguments[R]
ctx[R]
flag[R]
map_op[R]
return_type[R]

Public Class Methods

clear(bin_name, ctx: nil) click to toggle source

Create map clear operation. Server removes all items in map. Server returns null.

# File lib/aerospike/cdt/map_operation.rb, line 217
def self.clear(bin_name, ctx: nil)
  MapOperation.new(Operation::CDT_MODIFY, CLEAR, bin_name, ctx: ctx)
end
create(bin_name, order, persistent_index, ctx: nil) click to toggle source

Create map create operation. Server creates a map at the given context level.

@param [String] bin_name The bin name. @param [Integer] order The map order. @param [Boolean] persist_index If true, persist map index. A map index improves lookup performance,

but requires more storage. A map index can be created for a top-level
ordered map only. Nested and unordered map indexes are not supported.

@param [String] ctx Optional path to a nested map. If not defined, the top-level map is used.

# File lib/aerospike/cdt/map_operation.rb, line 122
def self.create(bin_name, order, persistent_index, ctx: nil)
  if !ctx || ctx.empty?
    # If context not defined, the set order for top-level bin map.
    attr = order[:attr]
    attr += 0x10 if persistent_index
    MapOperation.new(Operation::CDT_MODIFY, SET_TYPE, bin_name, attr, ctx: ctx, flag: order[:flag])
  else
    # Create nested map. persistIndex does not apply here, so ignore it
    MapOperation.new(Operation::CDT_MODIFY, SET_TYPE, bin_name, order[:attr], ctx: ctx, flag: order[:flag])
  end
end
decrement(bin_name, key, decr, ctx: nil, policy: MapPolicy::DEFAULT) click to toggle source

Create map decrement operation. Server decrements values by decr for all items identified by key and returns final result. Valid only for numbers.

The 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.

# File lib/aerospike/cdt/map_operation.rb, line 210
def self.decrement(bin_name, key, decr, ctx: nil, policy: MapPolicy::DEFAULT)
  MapOperation.new(Operation::CDT_MODIFY, DECREMENT, bin_name, key, decr, policy.order[:attr], ctx: ctx)
end
get_by_index(bin_name, index, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by index operation.

Server selects map item identified by index.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 588
def self.get_by_index(bin_name, index, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_INDEX, bin_name, index, ctx: ctx, return_type: return_type)
end
get_by_index_range(bin_name, index, count = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by index range operation.

Server selects “count” map items starting at specified index. If “count” is not specified, server selects map items starting at specified index to the end of map.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 600
def self.get_by_index_range(bin_name, index, count = nil, ctx: nil, return_type: MapReturnType::NONE)
  if count
    MapOperation.new(Operation::CDT_READ, GET_BY_INDEX_RANGE, bin_name, index, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_INDEX_RANGE, bin_name, index, ctx: ctx, return_type: return_type)
  end
end
get_by_key(bin_name, key, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by key operation. Server selects map item identified by key and returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 452
def self.get_by_key(bin_name, key, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_KEY, bin_name, key, ctx: ctx, return_type: return_type)
end
get_by_key_list(bin_name, keys, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by key list operation.

Server selects map items identified by keys.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 463
def self.get_by_key_list(bin_name, keys, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_KEY_LIST, bin_name, keys, ctx: ctx, return_type: return_type)
end
get_by_key_range(bin_name, key_begin, key_end = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by key range operation.

Server selects map items identified by key range (key_begin inclusive, key_end exclusive). If key_begin is null, the range is less than key_end. If key_end is null, the range is greater than equal to key_begin.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 475
def self.get_by_key_range(bin_name, key_begin, key_end = nil, ctx: nil, return_type: MapReturnType::NONE)
  if key_end
    MapOperation.new(Operation::CDT_READ, GET_BY_KEY_INTERVAL, bin_name, key_begin, key_end, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_KEY_INTERVAL, bin_name, key_begin, ctx: ctx, return_type: return_type)
  end
end
get_by_key_rel_index_range(bin_name, key, index, count = nil, ctx: nil, return_type: nil) click to toggle source

Create map get by key relative to index range operation.

Server selects “count” map items nearest to key and greater by relative index. If “count” is not specified, server selects map items nearest to key and greater by relative index, until the end of the map.

Server returns selected data specified by return_type.

Examples for map [{0=17},{4=2},{5=15},{9=10}]:

  • (value, index, count) = [selected items]

  • (5, 0, 1) = [{5=15}]

  • (5, 1, 2) = [{9=10}]

  • (5, -1, 1) = [{4=2}]

  • (3, 2, 1) = [{9=10}]

  • (3, -2, 2) = [{0=17}]

Without count:

  • (value, index) = [selected items]

  • (5, 0) = [{5=15}, {9=10}]

  • (5, 1) = [{9=10}]

  • (5, -1) = [{4=2}, {5=15}, {9=10}]

  • (3, 2) = [{9=10}]

  • (3, -2) = [{0=17}, {4=2}, {5=15}, {9=10}]

# File lib/aerospike/cdt/map_operation.rb, line 510
def self.get_by_key_rel_index_range(bin_name, key, index, count = nil, ctx: nil, return_type: nil)
  if count
    MapOperation.new(Operation::CDT_READ, GET_BY_KEY_REL_INDEX_RANGE, bin_name, key, index, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_KEY_REL_INDEX_RANGE, bin_name, key, index, ctx: ctx, return_type: return_type)
  end
end
get_by_rank(bin_name, rank, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by rank operation.

Server selects map item identified by rank.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 614
def self.get_by_rank(bin_name, rank, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_RANK, bin_name, rank, ctx: ctx, return_type: return_type)
end
get_by_rank_range(bin_name, rank, count = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by rank range operation.

Server selects “count” map items starting at specified rank. If “count” is not specified, server selects map items starting at specified rank to the last ranked item.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 625
def self.get_by_rank_range(bin_name, rank, count = nil, ctx: nil, return_type: MapReturnType::NONE)
  if count
    MapOperation.new(Operation::CDT_READ, GET_BY_RANK_RANGE, bin_name, rank, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_RANK_RANGE, bin_name, rank, ctx: ctx, return_type: return_type)
  end
end
get_by_value(bin_name, value, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by value operation.

Server selects map items identified by value.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 523
def self.get_by_value(bin_name, value, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_VALUE, bin_name, value, ctx: ctx, return_type: return_type)
end
get_by_value_list(bin_name, values, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by value list operation.

Server selects map items identified by value list.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 533
def self.get_by_value_list(bin_name, values, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_LIST, bin_name, values, ctx: ctx, return_type: return_type)
end
get_by_value_range(bin_name, value_begin, value_end = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map get by value range operation.

Server selects map items identified by value range (value_begin inclusive, value_end exclusive). If value_begin is null, the range is less than value_end. If value_end is null, the range is greater than equal to value_begin.

Server returns selected data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 545
def self.get_by_value_range(bin_name, value_begin, value_end = nil, ctx: nil, return_type: MapReturnType::NONE)
  if value_end
    MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_INTERVAL, bin_name, value_begin, value_end, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_INTERVAL, bin_name, value_begin, ctx: ctx, return_type: return_type)
  end
end
get_by_value_rel_rank_range(bin_name, value, rank, count = nil, ctx: nil, return_type: nil) click to toggle source

Create map get by value relative to rank range operation.

Server selects “count” map items nearest to value and greater by relative rank. If “count” is not specified, server selects map items nearest to value and greater by relative rank, until the end of the map.

Server returns selected data specified by return_type.

Examples for map [{4=2},{9=10},{5=15},{0=17}]:

  • (value, rank, count) = [selected items]

  • (11, 1, 1) = [{0=17}]

  • (11, -1, 1) = [{9=10}]

Without count:

  • (value, rank) = [selected items]

  • (11, 1) = [{0=17}]

  • (11, -1) = [{9=10}, {5=15}, {0=17}]

# File lib/aerospike/cdt/map_operation.rb, line 574
def self.get_by_value_rel_rank_range(bin_name, value, rank, count = nil, ctx: nil, return_type: nil)
  if count
    MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_REL_RANK_RANGE, bin_name, value, rank, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_READ, GET_BY_VALUE_REL_RANK_RANGE, bin_name, value, rank, ctx: ctx, return_type: return_type)
  end
end
increment(bin_name, key, incr, ctx: nil, policy: MapPolicy::DEFAULT) click to toggle source

Create map increment operation. Server increments values by incr for all items identified by key and returns final result. Valid only for numbers.

The 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.

# File lib/aerospike/cdt/map_operation.rb, line 199
def self.increment(bin_name, key, incr, ctx: nil, policy: MapPolicy::DEFAULT)
  MapOperation.new(Operation::CDT_MODIFY, INCREMENT, bin_name, key, incr, policy.order[:attr], ctx: ctx)
end
new(op_type, map_op, bin_name, *arguments, ctx: nil, return_type: nil, flag: nil) click to toggle source
# File lib/aerospike/cdt/map_operation.rb, line 101
def initialize(op_type, map_op, bin_name, *arguments, ctx: nil, return_type: nil, flag: nil)
  @op_type = op_type
  @bin_name = bin_name
  @bin_value = nil
  @map_op = map_op
  @ctx = ctx
  @flag = flag
  @arguments = arguments
  @return_type = return_type
  self
end
put(bin_name, key, value, ctx: nil, policy: MapPolicy::DEFAULT) click to toggle source

Create map put operation. Server writes key/value item to map bin and returns map size.

The 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.

# File lib/aerospike/cdt/map_operation.rb, line 154
def self.put(bin_name, key, value, ctx: nil, policy: MapPolicy::DEFAULT)
  if policy.flags == MapWriteFlags::DEFAULT
    case policy.write_mode
    when MapWriteMode::UPDATE_ONLY
      # Replace doesn't allow map order because it does not create on non-existing key.
      MapOperation.new(Operation::CDT_MODIFY, REPLACE, bin_name, key, value, ctx: ctx)
    when MapWriteMode::CREATE_ONLY
      MapOperation.new(Operation::CDT_MODIFY, ADD, bin_name, key, value, policy.order[:attr], ctx: ctx)
    else
      MapOperation.new(Operation::CDT_MODIFY, PUT, bin_name, key, value, policy.order[:attr], ctx: ctx)
    end
  else
    MapOperation.new(Operation::CDT_MODIFY, PUT, bin_name, key, value, policy.order[:attr], policy.flags, ctx: ctx)
  end
end
put_items(bin_name, values, ctx: nil, policy: MapPolicy::DEFAULT) click to toggle source

Create map put items operation Server writes each map item to map bin and returns map size.

The 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.

# File lib/aerospike/cdt/map_operation.rb, line 176
def self.put_items(bin_name, values, ctx: nil, policy: MapPolicy::DEFAULT)
  if policy.flags == MapWriteFlags::DEFAULT
    case policy.write_mode
    when MapWriteMode::UPDATE_ONLY
      # Replace doesn't allow map order because it does not create on non-existing key.
      MapOperation.new(Operation::CDT_MODIFY, REPLACE_ITEMS, bin_name, values, ctx: ctx)
    when MapWriteMode::CREATE_ONLY
      MapOperation.new(Operation::CDT_MODIFY, ADD_ITEMS, bin_name, values, policy.order[:attr], ctx: ctx)
    else
      MapOperation.new(Operation::CDT_MODIFY, PUT_ITEMS, bin_name, values, policy.order[:attr], ctx: ctx)
    end
  else
    MapOperation.new(Operation::CDT_MODIFY, PUT_ITEMS, bin_name, values, policy.order[:attr], policy.flags, ctx: ctx)
  end
end
remove_by_index(bin_name, index, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map item identified by index.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 394
def self.remove_by_index(bin_name, index, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX, bin_name, index, ctx: ctx, return_type: return_type)
end
remove_by_index_range(bin_name, index, count = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes “count” map items starting at specified index. If “count” is not specified, the server selects map items starting at specified index to the end of map.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 407
def self.remove_by_index_range(bin_name, index, count = nil, ctx: nil, return_type: MapReturnType::NONE)
  if count
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX_RANGE, bin_name, index, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_INDEX_RANGE, bin_name, index, ctx: ctx, return_type: return_type)
  end
end
remove_by_key(bin_name, key, ctx: nil, return_type: nil) click to toggle source

Create map remove operation.

Server removes map item identified by key and returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 226
def self.remove_by_key(bin_name, key, ctx: nil, return_type: nil)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY, bin_name, key, ctx: ctx, return_type: return_type)
end
remove_by_key_list(bin_name, keys, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by keys.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 236
def self.remove_by_key_list(bin_name, keys, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_LIST, bin_name, keys, ctx: ctx, return_type: return_type)
end
remove_by_key_range(bin_name, key_begin, key_end = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by key range (key_begin inclusive, key_end exclusive). If key_begin is null, the range is less than key_end. If key_end is null, the range is greater than equal to key_begin.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 264
def self.remove_by_key_range(bin_name, key_begin, key_end = nil, ctx: nil, return_type: MapReturnType::NONE)
  if key_end
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_INTERVAL, bin_name, key_begin, key_end, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_INTERVAL, bin_name, key_begin, ctx: ctx, return_type: return_type)
  end
end
remove_by_key_rel_index_range(bin_name, key, index, count = nil, ctx: nil, return_type: nil) click to toggle source

Create map remove by key relative to index range operation.

Server removes map items nearest to key and greater by relative index, with a count limit.

Server returns removed data specified by return_type.

Examples for map [{0=17},{4=2},{5=15},{9=10}]:

  • (value, index, count) = [removed items]

  • (5, 0, 1) = [{5=15}]

  • (5, 1, 2) = [{9=10}]

  • (5, -1, 1) = [{4=2}]

  • (3, 2, 1) = [{9=10}]

  • (3, -2, 2) = [{0=17}]

Without count:

  • (value, index) = [removed items]

  • (5, 0) = [{5=15}, {9=10}]

  • (5, 1) = [{9=10}]

  • (5, -1) = [{4=2}, {5=15}, {9=10}]

  • (3, 2) = [{9=10}]

  • (3, -2) = [{0=17}, {4=2}, {5=15}, {9=10}]

# File lib/aerospike/cdt/map_operation.rb, line 298
def self.remove_by_key_rel_index_range(bin_name, key, index, count = nil, ctx: nil, return_type: nil)
  if count
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_REL_INDEX_RANGE, bin_name, key, index, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_KEY_REL_INDEX_RANGE, bin_name, key, index, ctx: ctx, return_type: return_type)
  end
end
remove_by_rank(bin_name, rank, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map item identified by rank.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 422
def self.remove_by_rank(bin_name, rank, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK, bin_name, rank, ctx: ctx, return_type: return_type)
end
remove_by_rank_range(bin_name, rank, count = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server selects “count” map items starting at specified rank. If “count” is not specified, server removes map items starting at specified rank to the last ranked.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 434
def self.remove_by_rank_range(bin_name, rank, count = nil, ctx: nil, return_type: MapReturnType::NONE)
  if count
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK_RANGE, bin_name, rank, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_RANK_RANGE, bin_name, rank, ctx: ctx, return_type: return_type)
  end
end
remove_by_value(bin_name, value, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map item identified by value.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 312
def self.remove_by_value(bin_name, value, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE, bin_name, value, ctx: ctx, return_type: return_type)
end
remove_by_value_list(bin_name, values, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by value.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 322
def self.remove_by_value_list(bin_name, values, ctx: nil, return_type: MapReturnType::NONE)
  MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_LIST, bin_name, values, ctx: ctx, return_type: return_type)
end
remove_by_value_range(bin_name, value_begin, value_end = nil, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by value range (value_begin inclusive, value_end exclusive). If value_begin is null, the range is less than value_end. If value_end is null, the range is greater than equal to value_begin.

Server returns removed data specified by return_type.

# File lib/aerospike/cdt/map_operation.rb, line 351
def self.remove_by_value_range(bin_name, value_begin, value_end = nil, ctx: nil, return_type: MapReturnType::NONE)
  if value_end
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_INTERVAL, bin_name, value_begin, value_end, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_INTERVAL, bin_name, value_begin, ctx: ctx, return_type: return_type)
  end
end
remove_by_value_rel_rank_range(bin_name, value, rank, count = nil, ctx: nil, return_type: nil) click to toggle source

Create map remove by value relative to rank range operation.

Server removes “count” map items nearest to value and greater by relative rank. If “count” is not specified, server removes map items nearest to value and greater by relative rank, until the end of the map.

Server returns removed data specified by return_type.

Examples for map [{4=2},{9=10},{5=15},{0=17}]:

  • (value, rank, count) = [removed items]

  • (11, 1, 1) = [{0=17}]

  • (11, -1, 1) = [{9=10}]

Without count:

  • (value, rank) = [removed items]

  • (11, 1) = [{0=17}]

  • (11, -1) = [{9=10}, {5=15}, {0=17}]

# File lib/aerospike/cdt/map_operation.rb, line 380
def self.remove_by_value_rel_rank_range(bin_name, value, rank, count = nil, ctx: nil, return_type: nil)
  if count
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_REL_RANK_RANGE, bin_name, value, rank, count, ctx: ctx, return_type: return_type)
  else
    MapOperation.new(Operation::CDT_MODIFY, REMOVE_BY_VALUE_REL_RANK_RANGE, bin_name, value, rank, ctx: ctx, return_type: return_type)
  end
end
remove_keys(bin_name, *keys, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by keys.

Server returns removed data specified by return_type.

Deprecated. Use remove_by_key / remove_by_key_list instead.

# File lib/aerospike/cdt/map_operation.rb, line 248
def self.remove_keys(bin_name, *keys, ctx: nil, return_type: MapReturnType::NONE)
  if keys.length > 1
    remove_by_key_list(bin_name, keys, ctx: ctx, return_type: return_type)
  else
    remove_by_key(bin_name, keys.first, ctx: ctx, return_type: return_type)
  end
end
remove_values(bin_name, *values, ctx: nil, return_type: MapReturnType::NONE) click to toggle source

Create map remove operation.

Server removes map items identified by value.

Server returns removed data specified by return_type.

Deprecated. Use remove_by_value / remove_by_value_list instead.

# File lib/aerospike/cdt/map_operation.rb, line 334
def self.remove_values(bin_name, *values, ctx: nil, return_type: MapReturnType::NONE)
  if values.length > 1
    remove_by_value_list(bin_name, values, ctx: ctx, return_type: return_type)
  else
    remove_by_value(bin_name, values.first, ctx: ctx, return_type: return_type)
  end
end
set_policy(bin_name, policy, ctx: nil) click to toggle source

Create set map policy operation. Server sets map policy attributes. Server returns null.

The required map policy attributes can be changed after the map is created.

# File lib/aerospike/cdt/map_operation.rb, line 139
def self.set_policy(bin_name, policy, ctx: nil)
  attr = policy.attributes
  # Remove persistIndex flag for nested maps.
  if !ctx.nil? && !ctx.empty? && (attr & 0x10) != 0
    attr &= ~0x10
  end
  MapOperation.new(Operation::CDT_MODIFY, SET_TYPE, bin_name, attr, ctx: ctx)
end
size(bin_name, ctx: nil) click to toggle source

Create map size operation. Server returns size of map.

# File lib/aerospike/cdt/map_operation.rb, line 445
def self.size(bin_name, ctx: nil)
  MapOperation.new(Operation::CDT_READ, SIZE, bin_name, ctx: ctx)
end

Public Instance Methods

and_return(return_type) click to toggle source
# File lib/aerospike/cdt/map_operation.rb, line 633
def and_return(return_type)
  @return_type = return_type
  @bin_value = nil
  self
end
bin_value() click to toggle source
# File lib/aerospike/cdt/map_operation.rb, line 639
def bin_value
  @bin_value ||= pack_bin_value
end

Private Instance Methods

pack_bin_value() click to toggle source
# File lib/aerospike/cdt/map_operation.rb, line 645
def pack_bin_value
  bytes = nil

  args = arguments.dup
  args.unshift(return_type) if return_type

  Packer.use do |packer|
    if @ctx != nil && !@ctx.empty?
      packer.write_array_header(3)
      Value.of(0xff).pack(packer)

      pack_context(packer)

      packer.write_array_header(args.length+1)
      Value.of(@map_op).pack(packer)
    else
      packer.write_raw_short(@map_op)
      if !args.empty?
        packer.write_array_header(args.length)
      end
    end

    if !args.empty?
      args.each do |value|
        Value.of(value).pack(packer)
      end
    end
    bytes = packer.bytes
  end
  BytesValue.new(bytes)
end
pack_context(packer) click to toggle source
# File lib/aerospike/cdt/map_operation.rb, line 677
def pack_context(packer)
  packer.write_array_header(@ctx.length*2)
  if @flag
    (1...@ctx.length).each do |i|
      Value.of(@ctx[i].id).pack(packer)
      Value.of(@ctx[i].value).pack(packer)
    end

    Value.of(@ctx[-1].id | @flag).pack(packer)
    Value.of(@ctx[-1].value).pack(packer)
  else
    @ctx.each do |ctx|
      Value.of(ctx.id).pack(packer)
      Value.of(ctx.value).pack(packer)
    end
  end
end