Class: Aerospike::LargeList

Inherits:
Large
  • Object
show all
Defined in:
lib/aerospike/ldt/large_list.rb

Instance Method Summary collapse

Methods inherited from Large

#capacity, #capacity=, #config, #destroy, #scan, #size

Constructor Details

#initialize(client, policy, key, bin_name, user_module = nil) ⇒ LargeList

Returns a new instance of LargeList.



25
26
27
28
29
30
31
# File 'lib/aerospike/ldt/large_list.rb', line 25

def initialize(client, policy, key, bin_name, user_module=nil)
  @PACKAGE_NAME = 'llist'

  super(client, policy, key, bin_name, user_module)

  self
end

Instance Method Details

#add(*values) ⇒ Object

Add values to the list. If the list does not exist, create it using specified user_module configuration.

values values to add



36
37
38
39
40
41
42
# File 'lib/aerospike/ldt/large_list.rb', line 36

def add(*values)
  if values.length == 1
    @client.execute_udf(@key, @PACKAGE_NAME, 'add', [@bin_name, values[0], @user_module], @policy)
  else
    @client.execute_udf(@key, @PACKAGE_NAME, 'add_all', [@bin_name, values, @user_module], @policy)
  end
end

#filter(filter_name, *filter_args) ⇒ Object

Select values from list and apply specified Lua filter.

filter_name Lua function name which applies filter to returned list filter_args arguments to Lua function name returns list of entries selected



95
96
97
# File 'lib/aerospike/ldt/large_list.rb', line 95

def filter(filter_name, *filter_args)
  @client.execute_udf(@key, @PACKAGE_NAME, 'filter', [@bin_name, @user_module, filter_name, filter_args], @policy)
end

#find(value) ⇒ Object

Select values from list.

value value to select returns list of entries selected



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aerospike/ldt/large_list.rb', line 68

def find(value)
  begin
    @client.execute_udf(@key, @PACKAGE_NAME, 'find', [@bin_name, value], @policy)
  rescue Aerospike::Exceptions::Aerospike => e
    unless e.result_code == Aerospike::ResultCode::UDF_BAD_RESPONSE && e.message.index("Item Not Found")
      Aerospike.logger.error(e)
      raise e
    end
    nil
  end
end

#find_then_filter(value, filter_name, *filter_args) ⇒ Object

Select values from list and apply specified Lua filter.

value value to select filter_name Lua function name which applies filter to returned list filter_args arguments to Lua function name returns list of entries selected



86
87
88
# File 'lib/aerospike/ldt/large_list.rb', line 86

def find_then_filter(value, filter_name, *filter_args)
  @client.execute_udf(@key, @PACKAGE_NAME, 'find_then_filter', [@bin_name, value, @user_module, filter_name, filter_args], @policy)
end

#remove(value) ⇒ Object

Delete value from list.

value value to delete



60
61
62
# File 'lib/aerospike/ldt/large_list.rb', line 60

def remove(value)
  @client.execute_udf(@key, @PACKAGE_NAME, 'remove', [@bin_name, value], @policy)
end

#update(*values) ⇒ Object

Update/Add each value in array depending if key exists or not. 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 using specified user_module configuration.

values values to update



49
50
51
52
53
54
55
# File 'lib/aerospike/ldt/large_list.rb', line 49

def update(*values)
  if values.length == 1
    @client.execute_udf(@key, @PACKAGE_NAME, 'update', [@bin_name, values[0], @user_module], @policy)
  else
    @client.execute_udf(@key, @PACKAGE_NAME, 'update_all', [@bin_name, values, @user_module], @policy)
  end
end