aerospike 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +0 -0
  3. data/LICENSE +203 -0
  4. data/README.md +123 -0
  5. data/lib/aerospike.rb +69 -0
  6. data/lib/aerospike/aerospike_exception.rb +111 -0
  7. data/lib/aerospike/bin.rb +46 -0
  8. data/lib/aerospike/client.rb +649 -0
  9. data/lib/aerospike/cluster/cluster.rb +537 -0
  10. data/lib/aerospike/cluster/connection.rb +113 -0
  11. data/lib/aerospike/cluster/node.rb +248 -0
  12. data/lib/aerospike/cluster/node_validator.rb +85 -0
  13. data/lib/aerospike/cluster/partition.rb +54 -0
  14. data/lib/aerospike/cluster/partition_tokenizer_new.rb +128 -0
  15. data/lib/aerospike/cluster/partition_tokenizer_old.rb +135 -0
  16. data/lib/aerospike/command/batch_command.rb +120 -0
  17. data/lib/aerospike/command/batch_command_exists.rb +93 -0
  18. data/lib/aerospike/command/batch_command_get.rb +150 -0
  19. data/lib/aerospike/command/batch_item.rb +69 -0
  20. data/lib/aerospike/command/batch_node.rb +82 -0
  21. data/lib/aerospike/command/command.rb +680 -0
  22. data/lib/aerospike/command/delete_command.rb +57 -0
  23. data/lib/aerospike/command/execute_command.rb +42 -0
  24. data/lib/aerospike/command/exists_command.rb +57 -0
  25. data/lib/aerospike/command/field_type.rb +44 -0
  26. data/lib/aerospike/command/operate_command.rb +37 -0
  27. data/lib/aerospike/command/read_command.rb +174 -0
  28. data/lib/aerospike/command/read_header_command.rb +63 -0
  29. data/lib/aerospike/command/single_command.rb +60 -0
  30. data/lib/aerospike/command/touch_command.rb +50 -0
  31. data/lib/aerospike/command/write_command.rb +60 -0
  32. data/lib/aerospike/host.rb +43 -0
  33. data/lib/aerospike/info.rb +96 -0
  34. data/lib/aerospike/key.rb +99 -0
  35. data/lib/aerospike/language.rb +25 -0
  36. data/lib/aerospike/ldt/large.rb +69 -0
  37. data/lib/aerospike/ldt/large_list.rb +100 -0
  38. data/lib/aerospike/ldt/large_map.rb +82 -0
  39. data/lib/aerospike/ldt/large_set.rb +78 -0
  40. data/lib/aerospike/ldt/large_stack.rb +72 -0
  41. data/lib/aerospike/loggable.rb +55 -0
  42. data/lib/aerospike/operation.rb +70 -0
  43. data/lib/aerospike/policy/client_policy.rb +37 -0
  44. data/lib/aerospike/policy/generation_policy.rb +37 -0
  45. data/lib/aerospike/policy/policy.rb +54 -0
  46. data/lib/aerospike/policy/priority.rb +34 -0
  47. data/lib/aerospike/policy/record_exists_action.rb +45 -0
  48. data/lib/aerospike/policy/write_policy.rb +61 -0
  49. data/lib/aerospike/record.rb +42 -0
  50. data/lib/aerospike/result_code.rb +353 -0
  51. data/lib/aerospike/task/index_task.rb +59 -0
  52. data/lib/aerospike/task/task.rb +71 -0
  53. data/lib/aerospike/task/udf_register_task.rb +55 -0
  54. data/lib/aerospike/task/udf_remove_task.rb +55 -0
  55. data/lib/aerospike/udf.rb +24 -0
  56. data/lib/aerospike/utils/buffer.rb +139 -0
  57. data/lib/aerospike/utils/epoc.rb +28 -0
  58. data/lib/aerospike/utils/pool.rb +65 -0
  59. data/lib/aerospike/value/particle_type.rb +45 -0
  60. data/lib/aerospike/value/value.rb +380 -0
  61. data/lib/aerospike/version.rb +4 -0
  62. metadata +132 -0
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License'); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ require 'aerospike/ldt/large'
18
+
19
+ module Aerospike
20
+
21
+ private
22
+
23
+ class LargeList < Large
24
+
25
+ def initialize(client, policy, key, bin_name, user_module=nil)
26
+ @PACKAGE_NAME = 'llist'
27
+
28
+ super(client, policy, key, bin_name, user_module)
29
+
30
+ self
31
+ end
32
+
33
+ # Add values to the list. If the list does not exist, create it using specified user_module configuration.
34
+ #
35
+ # values values to add
36
+ def add(*values)
37
+ if values.length == 1
38
+ @client.execute_udf(@key, @PACKAGE_NAME, 'add', [@bin_name, values[0], @user_module], @policy)
39
+ else
40
+ @client.execute_udf(@key, @PACKAGE_NAME, 'add_all', [@bin_name, values, @user_module], @policy)
41
+ end
42
+ end
43
+
44
+ # Update/Add each value in array depending if key exists or not.
45
+ # If value is a map, the key is identified by "key" entry. Otherwise, the value is the key.
46
+ # If large list does not exist, create it using specified user_module configuration.
47
+ #
48
+ # values values to update
49
+ def update(*values)
50
+ if values.length == 1
51
+ @client.execute_udf(@key, @PACKAGE_NAME, 'update', [@bin_name, values[0], @user_module], @policy)
52
+ else
53
+ @client.execute_udf(@key, @PACKAGE_NAME, 'update_all', [@bin_name, values, @user_module], @policy)
54
+ end
55
+ end
56
+
57
+ # Delete value from list.
58
+ #
59
+ # value value to delete
60
+ def remove(value)
61
+ @client.execute_udf(@key, @PACKAGE_NAME, 'remove', [@bin_name, value], @policy)
62
+ end
63
+
64
+ # Select values from list.
65
+ #
66
+ # value value to select
67
+ # returns list of entries selected
68
+ def find(value)
69
+ begin
70
+ @client.execute_udf(@key, @PACKAGE_NAME, 'find', [@bin_name, value], @policy)
71
+ rescue Aerospike::Exceptions::Aerospike => e
72
+ unless e.result_code == Aerospike::ResultCode::UDF_BAD_RESPONSE && e.message.index("Item Not Found")
73
+ raise e
74
+ end
75
+ nil
76
+ end
77
+ end
78
+
79
+ # Select values from list and apply specified Lua filter.
80
+ #
81
+ # value value to select
82
+ # filter_name Lua function name which applies filter to returned list
83
+ # filter_args arguments to Lua function name
84
+ # returns list of entries selected
85
+ def find_then_filter(value, filter_name, *filter_args)
86
+ @client.execute_udf(@key, @PACKAGE_NAME, 'find_then_filter', [@bin_name, value, @user_module, filter_name, filter_args], @policy)
87
+ end
88
+
89
+ # Select values from list and apply specified Lua filter.
90
+ #
91
+ # filter_name Lua function name which applies filter to returned list
92
+ # filter_args arguments to Lua function name
93
+ # returns list of entries selected
94
+ def filter(filter_name, *filter_args)
95
+ @client.execute_udf(@key, @PACKAGE_NAME, 'filter', [@bin_name, @user_module, filter_name, filter_args], @policy)
96
+ end
97
+
98
+ end # class
99
+
100
+ end #class
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License'); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ require 'aerospike/ldt/large'
18
+
19
+ module Aerospike
20
+
21
+ private
22
+
23
+ class LargeMap < Large
24
+
25
+ def initialize(client, policy, key, bin_name, user_module=nil)
26
+ @PACKAGE_NAME = 'lmap'
27
+
28
+ super(client, policy, key, bin_name, user_module)
29
+
30
+ self
31
+ end
32
+
33
+ # Add entry to map. If the map does not exist, create it using specified user_module configuration.
34
+ #
35
+ # name entry key
36
+ # value entry value
37
+ def put(name, value)
38
+ @client.execute_udf(@key, @PACKAGE_NAME, 'put', [@bin_name, name, value, @user_module], @policy)
39
+ end
40
+
41
+ # Add map values to map. If the map does not exist, create it using specified user_module configuration.
42
+ #
43
+ # map map values to push
44
+ def put_map(the_map)
45
+ @client.execute_udf(@key, @PACKAGE_NAME, 'put_all', [@bin_name, the_map, @user_module], @policy)
46
+ end
47
+
48
+ # Get value from map given name key.
49
+ #
50
+ # name key.
51
+ # return map of items selected
52
+ def get(name)
53
+ begin
54
+ @client.execute_udf(@key, @PACKAGE_NAME, 'get', [@bin_name, name, @user_module], @policy)
55
+ rescue Aerospike::Exceptions::Aerospike => e
56
+ unless e.result_code == Aerospike::ResultCode::UDF_BAD_RESPONSE && e.message.index("Item Not Found")
57
+ raise e
58
+ end
59
+ nil
60
+ end
61
+ end
62
+
63
+ # Get value from map given name key.
64
+ #
65
+ # name key.
66
+ # return map of items selected
67
+ def remove(name)
68
+ @client.execute_udf(@key, @PACKAGE_NAME, 'remove', [@bin_name, name, @user_module], @policy)
69
+ end
70
+
71
+ # Select items from map.
72
+ #
73
+ # filter_name Lua function name which applies filter to returned list
74
+ # filter_args arguments to Lua function name
75
+ # return list of items selected
76
+ def filter(filter_name, *filter_args)
77
+ @client.execute_udf(@key, @PACKAGE_NAME, 'filter', [@bin_name, @user_module, filter_name, filter_args], @policy)
78
+ end
79
+
80
+ end # class
81
+
82
+ end #class
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License'); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ require 'aerospike/ldt/large'
18
+
19
+ module Aerospike
20
+
21
+ private
22
+
23
+ class LargeSet < Large
24
+
25
+ def initialize(client, policy, key, bin_name, user_module=nil)
26
+ @PACKAGE_NAME = 'lset'
27
+
28
+ super(client, policy, key, bin_name, user_module)
29
+
30
+ self
31
+ end
32
+
33
+ # Add values to the list. If the list does not exist, create it using specified user_module configuration.
34
+ #
35
+ # values values to add
36
+ def add(*values)
37
+ if values.length == 1
38
+ @client.execute_udf(@key, @PACKAGE_NAME, 'add', [@bin_name, values[0], @user_module], @policy)
39
+ else
40
+ @client.execute_udf(@key, @PACKAGE_NAME, 'add_all', [@bin_name, values, @user_module], @policy)
41
+ end
42
+ end
43
+
44
+ # Delete value from list.
45
+ #
46
+ # value value to delete
47
+ def remove(value)
48
+ @client.execute_udf(@key, @PACKAGE_NAME, 'remove', [@bin_name, value], @policy)
49
+ end
50
+
51
+ # Select values from list.
52
+ #
53
+ # value value to select
54
+ # returns list of entries selected
55
+ def get(value)
56
+ @client.execute_udf(@key, @PACKAGE_NAME, 'get', [@bin_name, value], @policy)
57
+ end
58
+
59
+ # Check existence of value in the set.
60
+ #
61
+ # value value to check
62
+ # returns true if found, otherwise false
63
+ def exists(value)
64
+ 1 == @client.execute_udf(@key, @PACKAGE_NAME, 'exists', [@bin_name, value], @policy)
65
+ end
66
+
67
+ # Select values from list and apply specified Lua filter.
68
+ #
69
+ # filter_name Lua function name which applies filter to returned list
70
+ # filter_args arguments to Lua function name
71
+ # returns list of entries selected
72
+ def filter(filter_name, *filter_args)
73
+ @client.execute_udf(@key, @PACKAGE_NAME, 'filter', [@bin_name, @user_module, filter_name, filter_args], @policy)
74
+ end
75
+
76
+ end # class
77
+
78
+ end #class
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the 'License'); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ require 'aerospike/ldt/large'
18
+
19
+ module Aerospike
20
+
21
+ private
22
+
23
+ class LargeStack < Large
24
+
25
+ def initialize(client, policy, key, bin_name, user_module=nil)
26
+ @PACKAGE_NAME = 'lstack'
27
+
28
+ super(client, policy, key, bin_name, user_module)
29
+
30
+ self
31
+ end
32
+
33
+ # Push values onto stack. If the stack does not exist, create it using specified user_module configuration.
34
+ #
35
+ # values values to push
36
+ def push(*values)
37
+ if values.length == 1
38
+ @client.execute_udf(@key, @PACKAGE_NAME, 'push', [@bin_name, values[0], @user_module], @policy)
39
+ else
40
+ @client.execute_udf(@key, @PACKAGE_NAME, 'push_all', [@bin_name, values, @user_module], @policy)
41
+ end
42
+ end
43
+
44
+ # Select items from top of stack.
45
+ #
46
+ # peek_count number of items to select.
47
+ # returns list of items selected
48
+ def peek(peek_count)
49
+ @client.execute_udf(@key, @PACKAGE_NAME, 'peek', [@bin_name, peek_count], @policy)
50
+ end
51
+
52
+ # Select items from top of stack.
53
+ #
54
+ # peek_count number of items to select.
55
+ # returns list of items selected
56
+ def pop(count)
57
+ @client.execute_udf(@key, @PACKAGE_NAME, 'pop', [@bin_name, count], @policy)
58
+ end
59
+
60
+ # Select items from top of stack.
61
+ #
62
+ # peek_count number of items to select.
63
+ # filter_name Lua function name which applies filter to returned list
64
+ # filter_args arguments to Lua function name
65
+ # returns list of items selected
66
+ def filter(peek_count, filter_name, *filter_args)
67
+ @client.execute_udf(@key, @PACKAGE_NAME, 'filter', [@bin_name, peek_count, @user_module, filter_name, filter_args], @policy)
68
+ end
69
+
70
+ end # class
71
+
72
+ end #class
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ module Aerospike
3
+
4
+ module Loggable
5
+
6
+ def self.log_operations(prefix, ops, runtime)
7
+ indent = " "*prefix.length
8
+ if ops.length == 1
9
+ Aerospike.logger.debug([ prefix, ops.first.log_inspect, "runtime: #{runtime}" ].join(' '))
10
+ else
11
+ first, *middle, last = ops
12
+ Aerospike.logger.debug([ prefix, first.log_inspect ].join(' '))
13
+ middle.each { |m| Aerospike.logger.debug([ indent, m.log_inspect ].join(' ')) }
14
+ Aerospike.logger.debug([ indent, last.log_inspect, "runtime: #{runtime}" ].join(' '))
15
+ end
16
+ end
17
+
18
+ def self.debug(prefix, payload, runtime)
19
+ Aerospike.logger.debug([ prefix, payload, "runtime: #{runtime}" ].join(' '))
20
+ end
21
+
22
+ def self.warn(prefix, payload, runtime)
23
+ Aerospike.logger.warn([ prefix, payload, "runtime: #{runtime}" ].join(' '))
24
+ end
25
+
26
+ def self.info(prefix, payload, runtime)
27
+ Aerospike.logger.info([ prefix, payload, "runtime: #{runtime}" ].join(' '))
28
+ end
29
+
30
+ def self.error(prefix, payload, runtime)
31
+ Aerospike.logger.error([ prefix, payload, "runtime: #{runtime}" ].join(' '))
32
+ end
33
+
34
+ def logger
35
+ return @logger if defined?(@logger)
36
+ @logger = rails_logger || default_logger
37
+ end
38
+
39
+ def rails_logger
40
+ defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
41
+ end
42
+
43
+ def default_logger
44
+ logger = Logger.new(STDOUT)
45
+ logger.level = Logger::ERROR
46
+ logger
47
+ end
48
+
49
+ def logger=(logger)
50
+ @logger = logger
51
+ end
52
+
53
+ end # module
54
+
55
+ end # module
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Portions may be licensed to Aerospike, Inc. under one or more contributor
5
+ # license agreements.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
8
+ # use this file except in compliance with the License. You may obtain a copy of
9
+ # the License at http:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+
17
+ require 'aerospike/value/value'
18
+
19
+ module Aerospike
20
+
21
+ class Operation
22
+
23
+ attr_reader :op_type, :bin_name, :bin_value
24
+
25
+ READ = 1
26
+ READ_HEADER = 1
27
+ WRITE = 2
28
+ ADD = 5
29
+ APPEND = 9
30
+ PREPEND = 10
31
+ TOUCH = 11
32
+
33
+ def initialize(op_type, bin_name=nil, bin_value=NullValue.new)
34
+ @op_type = op_type
35
+ @bin_name = bin_name
36
+ @bin_value = Value.of(bin_value)
37
+ self
38
+ end
39
+
40
+ def self.get(bin_name=nil)
41
+ Operation.new(READ, bin_name)
42
+ end
43
+
44
+ def self.get_header(bin_name=nil)
45
+ Operation.new(READ_HEADER, bin_name)
46
+ end
47
+
48
+ def self.put(bin)
49
+ Operation.new(WRITE, bin.name, bin.value)
50
+ end
51
+
52
+ def self.append(bin)
53
+ Operation.new(APPEND, bin.name, bin.value)
54
+ end
55
+
56
+ def self.prepend(bin)
57
+ Operation.new(PREPEND, bin.name, bin.value)
58
+ end
59
+
60
+ def self.add(bin)
61
+ Operation.new(ADD, bin.name, bin.value)
62
+ end
63
+
64
+ def self.touch
65
+ Operation.new(TOUCH)
66
+ end
67
+
68
+ end
69
+
70
+ end # module