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,45 @@
1
+ # encoding: utf-8
2
+ # Copyright 2014 Aerospike, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License")
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http:#www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Aerospike
17
+
18
+ module ParticleType
19
+
20
+ # Server particle types. Unsupported types are commented out.
21
+ NULL = 0
22
+ INTEGER = 1
23
+ #BIGNUM = 2
24
+ STRING = 3
25
+ BLOB = 4
26
+ #TIMESTAMP = 5
27
+ #DIGEST = 6
28
+ #JBLOB = 7
29
+ #CSHARP_BLOB = 8
30
+ #PYTHON_BLOB = 9
31
+ RUBY_BLOB = 10
32
+ #PHP_BLOB = 11
33
+ #ERLANG_BLOB = 12
34
+ #SEGMENT_POINTER = 13
35
+ #RTA_LIST = 14
36
+ #RTA_DICT = 15
37
+ #RTA_APPEND_DICT = 16
38
+ #RTA_APPEND_LIST = 17
39
+ #LUA_BLOB = 18
40
+ MAP = 19
41
+ LIST = 20
42
+
43
+ end # module
44
+
45
+ end # module
@@ -0,0 +1,380 @@
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 'msgpack'
18
+
19
+ require 'aerospike/utils/pool'
20
+
21
+ require 'aerospike/aerospike_exception'
22
+
23
+ module Aerospike
24
+
25
+ private
26
+
27
+ # Polymorphic value classes used to efficiently serialize objects into the wire protocol.
28
+ class Value
29
+
30
+ @@packer_pool = Pool.new
31
+ @@packer_pool.create_block = Proc.new { MessagePack::Packer.new }
32
+
33
+ def self.get_packer
34
+ res = @@packer_pool.poll
35
+ res.clear
36
+ res
37
+ end
38
+
39
+ def self.put_packer(packer)
40
+ @@packer_pool.offer(packer)
41
+ end
42
+
43
+ def self.of(value)
44
+ case value
45
+ when nil
46
+ res = NullValue.new
47
+ when Integer
48
+ if value < 2**63
49
+ res = IntegerValue.new(value)
50
+ else
51
+ # big nums > 2**63 are not supported
52
+ raise Aerospike::Exceptions::Aerospike.new(TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
53
+ end
54
+ when String
55
+ res = StringValue.new(value)
56
+ when Value
57
+ res = value
58
+ when Hash
59
+ res = MapValue.new(value)
60
+ when Array
61
+ res = ListValue.new(value)
62
+ else
63
+ # throw an exception for anything that is not supported.
64
+ raise Aerospike::Exceptions::Aerospike.new(TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
65
+ end
66
+
67
+ res
68
+ end
69
+
70
+ end # Value
71
+
72
+
73
+ # Empty value.
74
+ class NullValue < Value
75
+
76
+ def initialize
77
+ self
78
+ end
79
+
80
+ def type
81
+ Aerospike::ParticleType::NULL
82
+ end
83
+
84
+ def get
85
+ nil
86
+ end
87
+
88
+ def to_s
89
+ ''
90
+ end
91
+
92
+
93
+ def estimate_size
94
+ 0
95
+ end
96
+
97
+ def write(buffer, offset)
98
+ 0
99
+ end
100
+
101
+ def pack(packer)
102
+ packer.write_nil
103
+ end
104
+
105
+ def to_bytes
106
+ ''
107
+ end
108
+ end
109
+
110
+ # Byte array value.
111
+ class BytesValue < Value
112
+
113
+ def initialize(value)
114
+ @bytes = value
115
+ @bytes.force_encoding('binary')
116
+
117
+ self
118
+ end
119
+
120
+ def type
121
+ Aerospike::ParticleType::BLOB
122
+ end
123
+
124
+ def get
125
+ @bytes
126
+ end
127
+
128
+ def to_s
129
+ @bytes.to_s
130
+ end
131
+
132
+ def to_bytes
133
+ @bytes.bytes
134
+ end
135
+
136
+ def estimate_size
137
+ @bytes.bytesize
138
+ end
139
+
140
+ def write(buffer, offset)
141
+ buffer.write_binary(bytes, offset)
142
+ buffer.length
143
+ end
144
+
145
+ def pack(packer)
146
+ packer.write(@bytes.bytes)
147
+ end
148
+
149
+ end # BytesValue
150
+
151
+ #######################################
152
+
153
+ # value string.
154
+ class StringValue < Value
155
+
156
+ def initialize(val)
157
+ @value = val || ''
158
+ self
159
+ end
160
+
161
+ def estimate_size
162
+ @value.bytesize
163
+ end
164
+
165
+ def write(buffer, offset)
166
+ buffer.write_binary(@value, offset)
167
+ end
168
+
169
+ def pack(packer)
170
+ packer.write(@value)
171
+ end
172
+
173
+ def type
174
+ Aerospike::ParticleType::STRING
175
+ end
176
+
177
+ def get
178
+ @value
179
+ end
180
+
181
+ def to_bytes
182
+ @value
183
+ end
184
+
185
+ def to_s
186
+ @value
187
+ end
188
+
189
+ end # StringValue
190
+
191
+ #######################################
192
+
193
+ # Integer value.
194
+ class IntegerValue < Value
195
+
196
+ def initialize(val)
197
+ @value = val || 0
198
+ self
199
+ end
200
+
201
+ def estimate_size
202
+ 8
203
+ end
204
+
205
+ def write(buffer, offset)
206
+ buffer.write_int64(@value, offset)
207
+ 8
208
+ end
209
+
210
+ def pack(packer)
211
+ packer.write(@value)
212
+ end
213
+
214
+ def type
215
+ Aerospike::ParticleType::INTEGER
216
+ end
217
+
218
+ def get
219
+ @value
220
+ end
221
+
222
+ def to_bytes
223
+ [@value].pack('Q<')
224
+ end
225
+
226
+ def to_s
227
+ @value.to_s
228
+ end
229
+
230
+ end # IntegerValue
231
+
232
+ # List value.
233
+ # Supported by Aerospike 3 servers only.
234
+ class ListValue < Value
235
+
236
+ def initialize(list)
237
+ @list = list || nil
238
+ packer = Value.get_packer
239
+ pack(packer)
240
+ @bytes = packer.to_s.force_encoding('binary')
241
+ Value.put_packer(packer)
242
+
243
+ self
244
+ end
245
+
246
+ def estimate_size
247
+ @bytes.bytesize
248
+ end
249
+
250
+ def write(buffer, offset)
251
+ buffer.write_binary(@bytes, offset)
252
+ @bytes.bytesize
253
+ end
254
+
255
+ def pack(packer)
256
+ packer.write_array_header(@list.length)
257
+ # @list.each do |val|
258
+ for val in @list
259
+ Value.of(val).pack(packer)
260
+ end
261
+ end
262
+
263
+ def type
264
+ Aerospike::ParticleType::LIST
265
+ end
266
+
267
+ def get
268
+ @list
269
+ end
270
+
271
+ def to_bytes
272
+ @bytes
273
+ end
274
+
275
+ def to_s
276
+ @list.map{|v| v.to_s}.to_s
277
+ end
278
+
279
+ end
280
+
281
+ # #######################################/
282
+
283
+ # Map value.
284
+ # Supported by Aerospike 3 servers only.
285
+ class MapValue < Value
286
+
287
+ def initialize(vmap)
288
+ @vmap = vmap || {}
289
+
290
+ packer = Value.get_packer
291
+ pack(packer)
292
+ @bytes = packer.to_s.force_encoding('binary')
293
+ Value.put_packer(packer)
294
+
295
+ self
296
+ end
297
+
298
+ def estimate_size
299
+ @bytes.bytesize
300
+ end
301
+
302
+ def write(buffer, offset)
303
+ buffer.write_binary(@bytes, offset)
304
+ @bytes.bytesize
305
+ end
306
+
307
+ def pack(packer)
308
+ packer.write_map_header(@vmap.length)
309
+ # @vmap.each do |key, val|
310
+ for key, val in @vmap
311
+ Value.of(key).pack(packer)
312
+ Value.of(val).pack(packer)
313
+ end
314
+ end
315
+
316
+ def type
317
+ Aerospike::ParticleType::MAP
318
+ end
319
+
320
+ def get
321
+ @vmap
322
+ end
323
+
324
+ def to_bytes
325
+ @bytes
326
+ end
327
+
328
+ def to_s
329
+ @vmap.map{|k, v| "#{k.to_s} => #{v.to_s}" }.to_s
330
+ end
331
+
332
+ end
333
+
334
+ #######################################
335
+
336
+ protected
337
+
338
+ def self.bytes_to_particle(type, buf , offset, length)
339
+
340
+ case type
341
+ when Aerospike::ParticleType::STRING
342
+ # StringValue.new(buf.read(offset, length))
343
+ buf.read(offset, length)
344
+
345
+ when Aerospike::ParticleType::INTEGER
346
+ # IntegerValue.new(buf.read_int64(offset))
347
+ buf.read_int64(offset)
348
+
349
+ when Aerospike::ParticleType::BLOB
350
+ buf.read(offse,length)
351
+
352
+ when Aerospike::ParticleType::LIST
353
+ MessagePack.unpack(buf.read(offset, length))
354
+
355
+ when Aerospike::ParticleType::MAP
356
+ MessagePack.unpack(buf.read(offset, length))
357
+
358
+ else
359
+ nil
360
+ end
361
+ end
362
+
363
+ def self.bytes_to_key_value(type, buf, offset, len)
364
+
365
+ case type
366
+ when Aerospike::ParticleType::STRING
367
+ StringValue.new(buf.read(offset, len))
368
+
369
+ when Aerospike::ParticleType::INTEGER
370
+ IntegerValue.new(buf.read_var_int64(offset, len))
371
+
372
+ when Aerospike::ParticleType::BLOB
373
+ BytesValue.new(buf.read(offset,len))
374
+
375
+ else
376
+ nil
377
+ end
378
+ end
379
+
380
+ end # module
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module Aerospike
3
+ VERSION = "0.1.0"
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aerospike
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Khosrow Afroozeh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: atomic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: msgpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ description: Access your Aerospike cluster with ease of ruby.
42
+ email:
43
+ - khosrow@aerospike.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - LICENSE
50
+ - README.md
51
+ - lib/aerospike.rb
52
+ - lib/aerospike/aerospike_exception.rb
53
+ - lib/aerospike/bin.rb
54
+ - lib/aerospike/client.rb
55
+ - lib/aerospike/cluster/cluster.rb
56
+ - lib/aerospike/cluster/connection.rb
57
+ - lib/aerospike/cluster/node.rb
58
+ - lib/aerospike/cluster/node_validator.rb
59
+ - lib/aerospike/cluster/partition.rb
60
+ - lib/aerospike/cluster/partition_tokenizer_new.rb
61
+ - lib/aerospike/cluster/partition_tokenizer_old.rb
62
+ - lib/aerospike/command/batch_command.rb
63
+ - lib/aerospike/command/batch_command_exists.rb
64
+ - lib/aerospike/command/batch_command_get.rb
65
+ - lib/aerospike/command/batch_item.rb
66
+ - lib/aerospike/command/batch_node.rb
67
+ - lib/aerospike/command/command.rb
68
+ - lib/aerospike/command/delete_command.rb
69
+ - lib/aerospike/command/execute_command.rb
70
+ - lib/aerospike/command/exists_command.rb
71
+ - lib/aerospike/command/field_type.rb
72
+ - lib/aerospike/command/operate_command.rb
73
+ - lib/aerospike/command/read_command.rb
74
+ - lib/aerospike/command/read_header_command.rb
75
+ - lib/aerospike/command/single_command.rb
76
+ - lib/aerospike/command/touch_command.rb
77
+ - lib/aerospike/command/write_command.rb
78
+ - lib/aerospike/host.rb
79
+ - lib/aerospike/info.rb
80
+ - lib/aerospike/key.rb
81
+ - lib/aerospike/language.rb
82
+ - lib/aerospike/ldt/large.rb
83
+ - lib/aerospike/ldt/large_list.rb
84
+ - lib/aerospike/ldt/large_map.rb
85
+ - lib/aerospike/ldt/large_set.rb
86
+ - lib/aerospike/ldt/large_stack.rb
87
+ - lib/aerospike/loggable.rb
88
+ - lib/aerospike/operation.rb
89
+ - lib/aerospike/policy/client_policy.rb
90
+ - lib/aerospike/policy/generation_policy.rb
91
+ - lib/aerospike/policy/policy.rb
92
+ - lib/aerospike/policy/priority.rb
93
+ - lib/aerospike/policy/record_exists_action.rb
94
+ - lib/aerospike/policy/write_policy.rb
95
+ - lib/aerospike/record.rb
96
+ - lib/aerospike/result_code.rb
97
+ - lib/aerospike/task/index_task.rb
98
+ - lib/aerospike/task/task.rb
99
+ - lib/aerospike/task/udf_register_task.rb
100
+ - lib/aerospike/task/udf_remove_task.rb
101
+ - lib/aerospike/udf.rb
102
+ - lib/aerospike/utils/buffer.rb
103
+ - lib/aerospike/utils/epoc.rb
104
+ - lib/aerospike/utils/pool.rb
105
+ - lib/aerospike/value/particle_type.rb
106
+ - lib/aerospike/value/value.rb
107
+ - lib/aerospike/version.rb
108
+ homepage: http://www.aerospike.com
109
+ licenses:
110
+ - Apache2.0
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: An Aerospike driver for Ruby.
132
+ test_files: []