aerospike_native 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296cfb9cc494979027c364feb4637e48ddece680
4
- data.tar.gz: fce6ce9af517cfe235f3c9e387ecb9816d38ba39
3
+ metadata.gz: db77dc977496b4ace18450a71245fe8dcd0cf4aa
4
+ data.tar.gz: 535112b2da7532923df5281f0a02d1b3e90e72be
5
5
  SHA512:
6
- metadata.gz: 8ce57e918e11980f5fbc9bc33d2db296f271be0f0d6043575d0ca1bf3cd4ba2893d416357fd1593e3269121a543868d277761787be3ee8d03493081e0fbdbef8
7
- data.tar.gz: 4ff43fc3ec7bf72679014cce05a30efa09d5444c1c8a32ebc61122a43dd3c113eaa1aaef238fcd2e51b8678ff43dd236e7740c0e6ff74a998cfef8b27758a753
6
+ metadata.gz: 2757d76132519aa9c2abde4735bbab81d350f803cc538a524009bbceced035ed9543066ef2e98db627c8d1a267a2413098d82e13cae9c8058fdeee034121d1d0
7
+ data.tar.gz: 2c0b993989b2acbc8239fa745086b6dcdaca396cbcb51ada4b6d528519bf768ca41e8920137453f202cf664d3235590d881ae65cf439dbe93c90389799a41046
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AerospikeNative
2
2
 
3
- Ruby [aerospike](http://www.aerospike.com/) client with c extension (unstable)
3
+ Ruby [aerospike](http://www.aerospike.com/) client with c extension
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,11 +20,16 @@ Or install it yourself as:
20
20
 
21
21
  ## Current status
22
22
 
23
- * `operate` command with _write_, _increment_, _append_, _prepend_
23
+ * `operate` command with all operation types
24
24
  * `put` command
25
- * `get` command without digest keys support
26
- * Raw (bytes) type is not supported
25
+ * `get` command
26
+ * `remove` command
27
+ * `select` command
28
+ * `exixts?` command
29
+ * :disappointed: Raw (bytes) type is not supported
27
30
  * Supported timeout for policies
31
+ * Supported digest keys
32
+ * Supported exceptions (`AerospikeNative::Exception`) with several error codes constants like `AerospikeNative::Exception::ERR_CLIENT`
28
33
 
29
34
  ## Usage
30
35
 
@@ -36,7 +41,10 @@ key = AerospikeNative::Key.new('test', 'test', 'sample')
36
41
  client.put(key, {'bin1' => 1, 'bin2' => 'test'}, {'timeout' => 1})
37
42
  client.operate(key, [AerospikeNative::Operation.write('bin3', 25), AerospikeNative::Operation.increment('bin1', 2), AerospikeNative::Operation.append('bin1', '_aerospike')], {'timeout' => 1})
38
43
 
44
+ client.exists?(key)
39
45
  record = client.get(key)
46
+ record = client.select(key, ['bin2', 'bin1'])
47
+ client.remove(key)
40
48
  ```
41
49
 
42
50
  ## Contributing
@@ -157,9 +157,11 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
157
157
  Data_Get_Struct(vKey, as_key, key);
158
158
 
159
159
  if (aerospike_key_put(ptr, &err, &policy, key, &record) != AEROSPIKE_OK) {
160
+ as_record_destroy(&record);
160
161
  raise_aerospike_exception(err.code, err.message);
161
162
  }
162
163
 
164
+ as_record_destroy(&record);
163
165
  return Qtrue;
164
166
  }
165
167
 
@@ -211,6 +213,7 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
211
213
  Data_Get_Struct(vKey, as_key, key);
212
214
 
213
215
  if (aerospike_key_get(ptr, &err, &policy, key, &record) != AEROSPIKE_OK) {
216
+ as_record_destroy(record);
214
217
  raise_aerospike_exception(err.code, err.message);
215
218
  }
216
219
 
@@ -234,6 +237,7 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
234
237
  }
235
238
  }
236
239
 
240
+ as_record_destroy(record);
237
241
  return rb_class_new_instance(4, vParams, RecordClass);
238
242
  }
239
243
 
@@ -242,13 +246,17 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
242
246
  VALUE vKey;
243
247
  VALUE vOperations;
244
248
  VALUE vSettings = Qnil;
249
+ VALUE vParams[4];
245
250
  long idx = 0, n = 0;
251
+ bool isset_read = false;
246
252
 
247
253
  aerospike *ptr;
248
254
  as_operations ops;
249
255
  as_key* key;
250
256
  as_error err;
251
257
  as_policy_operate policy;
258
+ as_record* record = NULL;
259
+ as_bin bin;
252
260
 
253
261
  if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
254
262
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
@@ -308,6 +316,8 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
308
316
 
309
317
  break;
310
318
  case OPERATION_READ:
319
+ isset_read = true;
320
+ as_operations_add_read(&ops, StringValueCStr( bin_name ));
311
321
  break;
312
322
  case OPERATION_INCREMENT:
313
323
  as_operations_add_incr(&ops, StringValueCStr( bin_name ), NUM2INT( bin_value ));
@@ -331,15 +341,252 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
331
341
 
332
342
  Data_Get_Struct(vKey, as_key, key);
333
343
 
334
- if (aerospike_key_operate(ptr, &err, &policy, key, &ops, NULL) != AEROSPIKE_OK) {
344
+ if (isset_read) {
345
+ if (aerospike_key_operate(ptr, &err, &policy, key, &ops, &record) != AEROSPIKE_OK) {
346
+ as_operations_destroy(&ops);
347
+ as_record_destroy(record);
348
+ raise_aerospike_exception(err.code, err.message);
349
+ }
350
+
351
+ as_operations_destroy(&ops);
352
+
353
+ vParams[0] = vKey;
354
+ vParams[1] = rb_hash_new();
355
+ vParams[2] = UINT2NUM(record->gen);
356
+ vParams[3] = UINT2NUM(record->ttl);
357
+
358
+ for(n = 0; n < record->bins.size; n++) {
359
+ bin = record->bins.entries[n];
360
+ switch( as_val_type(bin.valuep) ) {
361
+ case AS_INTEGER:
362
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
363
+ break;
364
+ case AS_STRING:
365
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
366
+ break;
367
+ case AS_UNDEF:
368
+ default:
369
+ break;
370
+ }
371
+ }
372
+
373
+ as_record_destroy(record);
374
+ return rb_class_new_instance(4, vParams, RecordClass);
375
+ } else {
376
+ if (aerospike_key_operate(ptr, &err, &policy, key, &ops, NULL) != AEROSPIKE_OK) {
377
+ as_operations_destroy(&ops);
378
+ raise_aerospike_exception(err.code, err.message);
379
+ }
380
+
381
+ as_operations_destroy(&ops);
382
+ return Qtrue;
383
+ }
384
+ }
385
+
386
+ VALUE client_remove(int argc, VALUE* argv, VALUE vSelf)
387
+ {
388
+ VALUE vKey;
389
+ VALUE vSettings = Qnil;
390
+
391
+ aerospike *ptr;
392
+ as_key* key;
393
+ as_error err;
394
+ as_policy_remove policy;
395
+
396
+ if (argc > 2 || argc < 1) { // there should only be 1 or 2 arguments
397
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
398
+ }
399
+
400
+ vKey = argv[0];
401
+ check_aerospike_key(vKey);
402
+
403
+ if (argc == 2) {
404
+ vSettings = argv[1];
405
+
406
+ switch (TYPE(vSettings)) {
407
+ case T_NIL:
408
+ break;
409
+ case T_HASH: {
410
+ VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
411
+ if (TYPE(vTimeout) == T_FIXNUM) {
412
+ policy.timeout = NUM2UINT( vTimeout );
413
+ }
414
+ break;
415
+ }
416
+ default:
417
+ /* raise exception */
418
+ Check_Type(vSettings, T_HASH);
419
+ break;
420
+ }
421
+ }
422
+
423
+ Data_Get_Struct(vSelf, aerospike, ptr);
424
+ Data_Get_Struct(vKey, as_key, key);
425
+
426
+ if (aerospike_key_remove(ptr, &err, &policy, key) != AEROSPIKE_OK) {
335
427
  raise_aerospike_exception(err.code, err.message);
336
428
  }
337
429
 
338
- as_operations_destroy(&ops);
430
+ return Qtrue;
431
+ }
432
+
433
+ VALUE client_exists(int argc, VALUE* argv, VALUE vSelf)
434
+ {
435
+ VALUE vKey;
436
+ VALUE vSettings = Qnil;
437
+ VALUE vParams[4];
438
+
439
+ aerospike *ptr;
440
+ as_key* key;
441
+ as_error err;
442
+ as_policy_read policy;
443
+ as_record* record = NULL;
444
+ as_bin bin;
445
+ as_status status;
446
+ long n = 0;
447
+
448
+ if (argc > 2 || argc < 1) { // there should only be 1 or 2 arguments
449
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
450
+ }
451
+
452
+ vKey = argv[0];
453
+ check_aerospike_key(vKey);
454
+
455
+ if (argc == 2) {
456
+ vSettings = argv[1];
457
+
458
+ switch (TYPE(vSettings)) {
459
+ case T_NIL:
460
+ break;
461
+ case T_HASH: {
462
+ VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
463
+ if (TYPE(vTimeout) == T_FIXNUM) {
464
+ policy.timeout = NUM2UINT( vTimeout );
465
+ }
466
+ break;
467
+ }
468
+ default:
469
+ /* raise exception */
470
+ Check_Type(vSettings, T_HASH);
471
+ break;
472
+ }
473
+ }
474
+
475
+ Data_Get_Struct(vSelf, aerospike, ptr);
476
+ Data_Get_Struct(vKey, as_key, key);
477
+
478
+ status = aerospike_key_exists(ptr, &err, &policy, key, &record);
479
+ if (status != AEROSPIKE_OK && status != AEROSPIKE_ERR_RECORD_NOT_FOUND) {
480
+ as_record_destroy(record);
481
+ raise_aerospike_exception(err.code, err.message);
482
+ }
483
+ as_record_destroy(record);
484
+
485
+ if (status == AEROSPIKE_ERR_RECORD_NOT_FOUND) {
486
+ return Qfalse;
487
+ }
339
488
 
340
489
  return Qtrue;
341
490
  }
342
491
 
492
+ VALUE client_select(int argc, VALUE* argv, VALUE vSelf)
493
+ {
494
+ VALUE vKey;
495
+ VALUE vArray;
496
+ VALUE vSettings = Qnil;
497
+ VALUE vParams[4];
498
+
499
+ aerospike *ptr;
500
+ as_key* key;
501
+ as_error err;
502
+ as_policy_read policy;
503
+ as_record* record = NULL;
504
+ as_bin bin;
505
+ long n = 0, idx = 0;
506
+
507
+ if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
508
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
509
+ }
510
+
511
+ vKey = argv[0];
512
+ check_aerospike_key(vKey);
513
+ vArray = argv[1];
514
+
515
+ Check_Type(vArray, T_ARRAY);
516
+ idx = RARRAY_LEN(vArray);
517
+ if (idx == 0) {
518
+ return Qfalse;
519
+ }
520
+
521
+ if (argc == 3) {
522
+ vSettings = argv[2];
523
+
524
+ switch (TYPE(vSettings)) {
525
+ case T_NIL:
526
+ break;
527
+ case T_HASH: {
528
+ VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
529
+ if (TYPE(vTimeout) == T_FIXNUM) {
530
+ policy.timeout = NUM2UINT( vTimeout );
531
+ }
532
+ break;
533
+ }
534
+ default:
535
+ /* raise exception */
536
+ Check_Type(vSettings, T_HASH);
537
+ break;
538
+ }
539
+ }
540
+
541
+ Data_Get_Struct(vSelf, aerospike, ptr);
542
+ Data_Get_Struct(vKey, as_key, key);
543
+ const char* bins[idx];
544
+
545
+ for(n = 0; n < idx; n++) {
546
+ VALUE bin_name = rb_ary_entry(vArray, n);
547
+
548
+ Check_Type(bin_name, T_STRING);
549
+ char* name = StringValueCStr( bin_name );
550
+ bins[n] = malloc(strlen(name) * sizeof(char) + 1);
551
+ memset(bins[n], '\0', strlen(name) + 1);
552
+ strcpy(bins[n], name);
553
+ }
554
+
555
+ if (aerospike_key_select(ptr, &err, &policy, key, bins, &record) != AEROSPIKE_OK) {
556
+ for(n = 0; n < idx; n++) {
557
+ free(bins[n]);
558
+ }
559
+ as_record_destroy(record);
560
+ raise_aerospike_exception(err.code, err.message);
561
+ }
562
+ for(n = 0; n < idx; n++) {
563
+ free(bins[n]);
564
+ }
565
+
566
+ vParams[0] = vKey;
567
+ vParams[1] = rb_hash_new();
568
+ vParams[2] = UINT2NUM(record->gen);
569
+ vParams[3] = UINT2NUM(record->ttl);
570
+
571
+ for(n = 0; n < record->bins.size; n++) {
572
+ bin = record->bins.entries[n];
573
+ switch( as_val_type(bin.valuep) ) {
574
+ case AS_INTEGER:
575
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
576
+ break;
577
+ case AS_STRING:
578
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
579
+ break;
580
+ case AS_UNDEF:
581
+ default:
582
+ break;
583
+ }
584
+ }
585
+
586
+ as_record_destroy(record);
587
+ return rb_class_new_instance(4, vParams, RecordClass);
588
+ }
589
+
343
590
  void define_client()
344
591
  {
345
592
  ClientClass = rb_define_class_under(AerospikeNativeClass, "Client", rb_cObject);
@@ -348,4 +595,7 @@ void define_client()
348
595
  rb_define_method(ClientClass, "operate", client_operate, -1);
349
596
  rb_define_method(ClientClass, "put", client_put, -1);
350
597
  rb_define_method(ClientClass, "get", client_get, -1);
598
+ rb_define_method(ClientClass, "remove", client_remove, -1);
599
+ rb_define_method(ClientClass, "exists?", client_exists, -1);
600
+ rb_define_method(ClientClass, "select", client_select, -1);
351
601
  }
@@ -40,6 +40,6 @@ void raise_aerospike_exception(int iCode, char* sMessage)
40
40
  VALUE vException;
41
41
 
42
42
  vException = rb_exc_new2(ExceptionClass, sMessage);
43
- rb_iv_set(vException, "@code", iCode);
43
+ rb_iv_set(vException, "@code", INT2FIX(iCode));
44
44
  rb_exc_raise(vException);
45
45
  }
@@ -4,8 +4,16 @@ VALUE OperationClass;
4
4
 
5
5
  VALUE operation_initialize(VALUE vSelf, VALUE vOpType, VALUE vBinName, VALUE vBinValue)
6
6
  {
7
+ int op_type = 0;
8
+
7
9
  Check_Type(vOpType, T_FIXNUM);
8
- Check_Type(vBinName, T_STRING);
10
+ op_type = NUM2INT(vOpType);
11
+
12
+ if (op_type != OPERATION_TOUCH) {
13
+ Check_Type(vBinName, T_STRING);
14
+ } else {
15
+ Check_Type(vBinName, T_NIL);
16
+ }
9
17
 
10
18
  rb_iv_set(vSelf, "@op_type", vOpType);
11
19
  rb_iv_set(vSelf, "@bin_name", vBinName);
@@ -59,6 +67,26 @@ VALUE operation_increment(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
59
67
  return rb_class_new_instance(3, vArgs, vSelf);
60
68
  }
61
69
 
70
+ VALUE operation_touch(VALUE vSelf)
71
+ {
72
+ VALUE vArgs[3];
73
+
74
+ vArgs[0] = INT2NUM(OPERATION_TOUCH);
75
+ vArgs[1] = Qnil;
76
+ vArgs[2] = Qnil;
77
+ return rb_class_new_instance(3, vArgs, vSelf);
78
+ }
79
+
80
+ VALUE operation_read(VALUE vSelf, VALUE vBinName)
81
+ {
82
+ VALUE vArgs[3];
83
+
84
+ vArgs[0] = INT2NUM(OPERATION_READ);
85
+ vArgs[1] = vBinName;
86
+ vArgs[2] = Qnil;
87
+ return rb_class_new_instance(3, vArgs, vSelf);
88
+ }
89
+
62
90
  void define_operation()
63
91
  {
64
92
  OperationClass = rb_define_class_under(AerospikeNativeClass, "Operation", rb_cObject);
@@ -67,6 +95,8 @@ void define_operation()
67
95
  rb_define_singleton_method(OperationClass, "append", operation_append, 2);
68
96
  rb_define_singleton_method(OperationClass, "prepend", operation_prepend, 2);
69
97
  rb_define_singleton_method(OperationClass, "increment", operation_increment, 2);
98
+ rb_define_singleton_method(OperationClass, "touch", operation_touch, 0);
99
+ rb_define_singleton_method(OperationClass, "read", operation_read, 1);
70
100
  rb_define_attr(OperationClass, "op_type", 1, 0);
71
101
  rb_define_attr(OperationClass, "bin_name", 1, 0);
72
102
  rb_define_attr(OperationClass, "bin_value", 1, 0);
@@ -1,3 +1,3 @@
1
1
  module AerospikeNative
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aerospike_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Ziablitskii