aerospike_native 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/aerospike_native/aerospike_native.c +2 -0
- data/ext/aerospike_native/client.c +121 -146
- data/ext/aerospike_native/common.h +155 -12
- data/ext/aerospike_native/condition.c +3 -3
- data/ext/aerospike_native/key.c +8 -1
- data/ext/aerospike_native/operation.c +42 -0
- data/ext/aerospike_native/policy.c +34 -0
- data/ext/aerospike_native/policy.h +10 -0
- data/ext/aerospike_native/record.c +52 -0
- data/ext/aerospike_native/record.h +3 -0
- data/lib/aerospike_native/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a4c1501ed65384aa0a0d8dd90db474e0ff72de
|
4
|
+
data.tar.gz: 04e3a37359e96e9a753fb2dd88ab1251d68d9290
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ceaf60e6dbe985eee662d96f931af9caf2a95573f3612a0b53411cf38fd57da4f0e9713092883eaf41301b665ea1bd29e8c1f9792356b62773d2978c54aa3d6
|
7
|
+
data.tar.gz: b962db5ee9f2f2d394424c3a7eeaee3f36ff14f613d727337e3251abbb4518881f3e4077fd5ba2591d5543cd5ae81332eb325dd39d9ee6500d5c30beb5e7f34d
|
data/README.md
CHANGED
@@ -28,9 +28,9 @@ Or install it yourself as:
|
|
28
28
|
* `exixts?` command
|
29
29
|
* `where` command (query support)
|
30
30
|
* :disappointed: Raw (bytes) type is not supported
|
31
|
-
* Supported
|
31
|
+
* Supported policies with all parameters for described commands
|
32
32
|
* Supported digest keys
|
33
|
-
* Supported exceptions (`AerospikeNative::Exception`) with several error codes constants
|
33
|
+
* Supported exceptions (`AerospikeNative::Exception`) with several error codes constants `AerospikeNative::Exception.constants`
|
34
34
|
* Index management (`create_index` and `drop_index`)
|
35
35
|
|
36
36
|
## Usage
|
@@ -4,6 +4,7 @@
|
|
4
4
|
#include "operation.h"
|
5
5
|
#include "record.h"
|
6
6
|
#include "condition.h"
|
7
|
+
#include "policy.h"
|
7
8
|
|
8
9
|
VALUE AerospikeNativeClass;
|
9
10
|
|
@@ -16,6 +17,7 @@ void Init_aerospike_native()
|
|
16
17
|
define_record();
|
17
18
|
define_operation();
|
18
19
|
define_condition();
|
20
|
+
define_policy();
|
19
21
|
|
20
22
|
rb_define_const(AerospikeNativeClass, "INDEX_NUMERIC", INT2FIX(INDEX_NUMERIC));
|
21
23
|
rb_define_const(AerospikeNativeClass, "INDEX_STRING", INT2FIX(INDEX_STRING));
|
@@ -30,6 +30,13 @@ static VALUE client_allocate(VALUE klass)
|
|
30
30
|
return obj;
|
31
31
|
}
|
32
32
|
|
33
|
+
/*
|
34
|
+
* call-seq:
|
35
|
+
* new() -> AerospikeNative::Client
|
36
|
+
* new(hosts) -> AerospikeNative::Client
|
37
|
+
*
|
38
|
+
* initialize new client, use {'host' => ..., 'port' => ...} for each hosts element
|
39
|
+
*/
|
33
40
|
VALUE client_initialize(int argc, VALUE* argv, VALUE self)
|
34
41
|
{
|
35
42
|
VALUE ary = Qnil;
|
@@ -82,6 +89,13 @@ VALUE client_initialize(int argc, VALUE* argv, VALUE self)
|
|
82
89
|
return self;
|
83
90
|
}
|
84
91
|
|
92
|
+
/*
|
93
|
+
* call-seq:
|
94
|
+
* put(key, bins) -> true or false
|
95
|
+
* put(key, bins, policy_settings) -> true or false
|
96
|
+
*
|
97
|
+
* put bins to specified key, bins are hash
|
98
|
+
*/
|
85
99
|
VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
|
86
100
|
{
|
87
101
|
VALUE vKey;
|
@@ -108,8 +122,8 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
|
|
108
122
|
|
109
123
|
as_policy_write_init(&policy);
|
110
124
|
|
111
|
-
if (argc == 3) {
|
112
|
-
|
125
|
+
if (argc == 3 && TYPE(vArgs[2]) != T_NIL) {
|
126
|
+
SET_WRITE_POLICY(policy, vArgs[2]);
|
113
127
|
}
|
114
128
|
|
115
129
|
idx = RHASH_SIZE(vBins);
|
@@ -135,7 +149,7 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
|
|
135
149
|
as_record_set_int64(&record, StringValueCStr(bin_name), NUM2LONG(bin_value));
|
136
150
|
break;
|
137
151
|
default:
|
138
|
-
rb_raise(
|
152
|
+
rb_raise(rb_eTypeError, "wrong argument type for bin value (expected Fixnum or String)");
|
139
153
|
break;
|
140
154
|
}
|
141
155
|
}
|
@@ -151,19 +165,22 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
|
|
151
165
|
return Qtrue;
|
152
166
|
}
|
153
167
|
|
168
|
+
/*
|
169
|
+
* call-seq:
|
170
|
+
* get(key) -> AerospikeNative::Record
|
171
|
+
* get(key, policy_settings) -> AerospikeNative::Record
|
172
|
+
*
|
173
|
+
* get record
|
174
|
+
*/
|
154
175
|
VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
|
155
176
|
{
|
156
177
|
VALUE vKey;
|
157
|
-
VALUE vParams[4];
|
158
178
|
|
159
179
|
aerospike *ptr;
|
160
180
|
as_key* key;
|
161
181
|
as_error err;
|
162
182
|
as_record* record = NULL;
|
163
183
|
as_policy_read policy;
|
164
|
-
as_bin bin;
|
165
|
-
|
166
|
-
int n = 0;
|
167
184
|
|
168
185
|
if (argc > 2 || argc < 1) { // there should only be 1 or 2 arguments
|
169
186
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
@@ -174,8 +191,8 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
|
|
174
191
|
|
175
192
|
as_policy_read_init(&policy);
|
176
193
|
|
177
|
-
if (argc == 2) {
|
178
|
-
|
194
|
+
if (argc == 2 && TYPE(vArgs[1]) != T_NIL) {
|
195
|
+
SET_READ_POLICY(policy, vArgs[1]);
|
179
196
|
}
|
180
197
|
|
181
198
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
@@ -186,35 +203,20 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
|
|
186
203
|
raise_aerospike_exception(err.code, err.message);
|
187
204
|
}
|
188
205
|
|
189
|
-
|
190
|
-
vParams[1] = rb_hash_new();
|
191
|
-
vParams[2] = UINT2NUM(record->gen);
|
192
|
-
vParams[3] = UINT2NUM(record->ttl);
|
193
|
-
|
194
|
-
for(n = 0; n < record->bins.size; n++) {
|
195
|
-
bin = record->bins.entries[n];
|
196
|
-
switch( as_val_type(bin.valuep) ) {
|
197
|
-
case AS_INTEGER:
|
198
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
|
199
|
-
break;
|
200
|
-
case AS_STRING:
|
201
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
202
|
-
break;
|
203
|
-
case AS_UNDEF:
|
204
|
-
default:
|
205
|
-
break;
|
206
|
-
}
|
207
|
-
}
|
208
|
-
|
209
|
-
as_record_destroy(record);
|
210
|
-
return rb_class_new_instance(4, vParams, RecordClass);
|
206
|
+
return rb_record_from_c(record, key);
|
211
207
|
}
|
212
208
|
|
209
|
+
/*
|
210
|
+
* call-seq:
|
211
|
+
* operate(key, operations) -> true, false or AerospikeNative::Record
|
212
|
+
* operate(key, operations, policy_settings) -> true, false or AerospikeNative::Record
|
213
|
+
*
|
214
|
+
* perform multiple operations in one transaction, operations are array of AerospikeNative::Operation
|
215
|
+
*/
|
213
216
|
VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
214
217
|
{
|
215
218
|
VALUE vKey;
|
216
219
|
VALUE vOperations;
|
217
|
-
VALUE vParams[4];
|
218
220
|
long idx = 0, n = 0;
|
219
221
|
bool isset_read = false;
|
220
222
|
|
@@ -224,7 +226,6 @@ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
|
224
226
|
as_error err;
|
225
227
|
as_policy_operate policy;
|
226
228
|
as_record* record = NULL;
|
227
|
-
as_bin bin;
|
228
229
|
|
229
230
|
if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
|
230
231
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
|
@@ -237,8 +238,8 @@ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
|
237
238
|
Check_Type(vOperations, T_ARRAY);
|
238
239
|
as_policy_operate_init(&policy);
|
239
240
|
|
240
|
-
if (argc == 3) {
|
241
|
-
|
241
|
+
if (argc == 3 && TYPE(vArgs[2]) != T_NIL) {
|
242
|
+
SET_OPERATE_POLICY(policy, vArgs[2]);
|
242
243
|
}
|
243
244
|
|
244
245
|
idx = RARRAY_LEN(vOperations);
|
@@ -303,28 +304,7 @@ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
|
303
304
|
|
304
305
|
as_operations_destroy(&ops);
|
305
306
|
|
306
|
-
|
307
|
-
vParams[1] = rb_hash_new();
|
308
|
-
vParams[2] = UINT2NUM(record->gen);
|
309
|
-
vParams[3] = UINT2NUM(record->ttl);
|
310
|
-
|
311
|
-
for(n = 0; n < record->bins.size; n++) {
|
312
|
-
bin = record->bins.entries[n];
|
313
|
-
switch( as_val_type(bin.valuep) ) {
|
314
|
-
case AS_INTEGER:
|
315
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
|
316
|
-
break;
|
317
|
-
case AS_STRING:
|
318
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
319
|
-
break;
|
320
|
-
case AS_UNDEF:
|
321
|
-
default:
|
322
|
-
break;
|
323
|
-
}
|
324
|
-
}
|
325
|
-
|
326
|
-
as_record_destroy(record);
|
327
|
-
return rb_class_new_instance(4, vParams, RecordClass);
|
307
|
+
return rb_record_from_c(record, key);
|
328
308
|
} else {
|
329
309
|
if (aerospike_key_operate(ptr, &err, &policy, key, &ops, NULL) != AEROSPIKE_OK) {
|
330
310
|
as_operations_destroy(&ops);
|
@@ -336,6 +316,13 @@ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
|
336
316
|
}
|
337
317
|
}
|
338
318
|
|
319
|
+
/*
|
320
|
+
* call-seq:
|
321
|
+
* remove(key) -> true or false
|
322
|
+
* remove(key, policy_settings) -> true or false
|
323
|
+
*
|
324
|
+
* remove record
|
325
|
+
*/
|
339
326
|
VALUE client_remove(int argc, VALUE* vArgs, VALUE vSelf)
|
340
327
|
{
|
341
328
|
VALUE vKey;
|
@@ -352,8 +339,8 @@ VALUE client_remove(int argc, VALUE* vArgs, VALUE vSelf)
|
|
352
339
|
vKey = vArgs[0];
|
353
340
|
check_aerospike_key(vKey);
|
354
341
|
|
355
|
-
if (argc == 2) {
|
356
|
-
|
342
|
+
if (argc == 2 && TYPE(vArgs[2]) != T_NIL) {
|
343
|
+
SET_REMOVE_POLICY(policy, vArgs[2]);
|
357
344
|
}
|
358
345
|
|
359
346
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
@@ -366,6 +353,13 @@ VALUE client_remove(int argc, VALUE* vArgs, VALUE vSelf)
|
|
366
353
|
return Qtrue;
|
367
354
|
}
|
368
355
|
|
356
|
+
/*
|
357
|
+
* call-seq:
|
358
|
+
* exists?(key) -> true or false
|
359
|
+
* exists?(key, policy_settings) -> true or false
|
360
|
+
*
|
361
|
+
* check existing record by key
|
362
|
+
*/
|
369
363
|
VALUE client_exists(int argc, VALUE* vArgs, VALUE vSelf)
|
370
364
|
{
|
371
365
|
VALUE vKey;
|
@@ -384,8 +378,8 @@ VALUE client_exists(int argc, VALUE* vArgs, VALUE vSelf)
|
|
384
378
|
vKey = vArgs[0];
|
385
379
|
check_aerospike_key(vKey);
|
386
380
|
|
387
|
-
if (argc == 2) {
|
388
|
-
|
381
|
+
if (argc == 2 && TYPE(vArgs[1]) != T_NIL) {
|
382
|
+
SET_READ_POLICY(policy, vArgs[1]);
|
389
383
|
}
|
390
384
|
|
391
385
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
@@ -405,18 +399,23 @@ VALUE client_exists(int argc, VALUE* vArgs, VALUE vSelf)
|
|
405
399
|
return Qtrue;
|
406
400
|
}
|
407
401
|
|
402
|
+
/*
|
403
|
+
* call-seq:
|
404
|
+
* select(key, bins) -> AerospikeNative::Record
|
405
|
+
* select(key, bins, policy_settings) -> AerospikeNative::Record
|
406
|
+
*
|
407
|
+
* select specified bins by key
|
408
|
+
*/
|
408
409
|
VALUE client_select(int argc, VALUE* vArgs, VALUE vSelf)
|
409
410
|
{
|
410
411
|
VALUE vKey;
|
411
412
|
VALUE vArray;
|
412
|
-
VALUE vParams[4];
|
413
413
|
|
414
414
|
aerospike *ptr;
|
415
415
|
as_key* key;
|
416
416
|
as_error err;
|
417
417
|
as_policy_read policy;
|
418
418
|
as_record* record = NULL;
|
419
|
-
as_bin bin;
|
420
419
|
long n = 0, idx = 0;
|
421
420
|
|
422
421
|
if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
|
@@ -433,8 +432,8 @@ VALUE client_select(int argc, VALUE* vArgs, VALUE vSelf)
|
|
433
432
|
return Qfalse;
|
434
433
|
}
|
435
434
|
|
436
|
-
if (argc == 3) {
|
437
|
-
|
435
|
+
if (argc == 3 && TYPE(vArgs[2]) != T_NIL) {
|
436
|
+
SET_READ_POLICY(policy, vArgs[2]);
|
438
437
|
}
|
439
438
|
|
440
439
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
@@ -462,30 +461,16 @@ VALUE client_select(int argc, VALUE* vArgs, VALUE vSelf)
|
|
462
461
|
free(bins[n]);
|
463
462
|
}
|
464
463
|
|
465
|
-
|
466
|
-
vParams[1] = rb_hash_new();
|
467
|
-
vParams[2] = UINT2NUM(record->gen);
|
468
|
-
vParams[3] = UINT2NUM(record->ttl);
|
469
|
-
|
470
|
-
for(n = 0; n < record->bins.size; n++) {
|
471
|
-
bin = record->bins.entries[n];
|
472
|
-
switch( as_val_type(bin.valuep) ) {
|
473
|
-
case AS_INTEGER:
|
474
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
|
475
|
-
break;
|
476
|
-
case AS_STRING:
|
477
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
478
|
-
break;
|
479
|
-
case AS_UNDEF:
|
480
|
-
default:
|
481
|
-
break;
|
482
|
-
}
|
483
|
-
}
|
484
|
-
|
485
|
-
as_record_destroy(record);
|
486
|
-
return rb_class_new_instance(4, vParams, RecordClass);
|
464
|
+
return rb_record_from_c(record, key);
|
487
465
|
}
|
488
466
|
|
467
|
+
/*
|
468
|
+
* call-seq:
|
469
|
+
* create_index(namespace, set, bin_name, index_name) -> true or false
|
470
|
+
* create_index(namespace, set, bin_name, index_name, policy_settings) -> true or false
|
471
|
+
*
|
472
|
+
* Create new index, use {'type' => AerospikeNative::INDEX_NUMERIC or AerospikeNative::INDEX_STRING} as policy_settings to define index type
|
473
|
+
*/
|
489
474
|
VALUE client_create_index(int argc, VALUE* vArgs, VALUE vSelf)
|
490
475
|
{
|
491
476
|
VALUE vNamespace, vSet, vBinName, vIndexName;
|
@@ -512,9 +497,9 @@ VALUE client_create_index(int argc, VALUE* vArgs, VALUE vSelf)
|
|
512
497
|
vIndexName = vArgs[3];
|
513
498
|
Check_Type(vIndexName, T_STRING);
|
514
499
|
|
515
|
-
if (argc == 5) {
|
500
|
+
if (argc == 5 && TYPE(vArgs[4]) != T_NIL) {
|
516
501
|
VALUE vType = Qnil;
|
517
|
-
|
502
|
+
SET_INFO_POLICY(policy, vArgs[4]);
|
518
503
|
vType = rb_hash_aref(vArgs[4], rb_str_new2("type"));
|
519
504
|
if (TYPE(vType) == T_FIXNUM) {
|
520
505
|
switch(FIX2INT(vType)) {
|
@@ -544,13 +529,22 @@ VALUE client_create_index(int argc, VALUE* vArgs, VALUE vSelf)
|
|
544
529
|
|
545
530
|
task.as = ptr;
|
546
531
|
strcpy(task.ns, StringValueCStr(vNamespace));
|
547
|
-
strcpy(task.name, StringValueCStr(
|
532
|
+
strcpy(task.name, StringValueCStr(vIndexName));
|
548
533
|
task.done = false;
|
549
|
-
aerospike_index_create_wait(&err, &task, 1000)
|
534
|
+
if (aerospike_index_create_wait(&err, &task, 1000) != AEROSPIKE_OK) {
|
535
|
+
raise_aerospike_exception(err.code, err.message);
|
536
|
+
}
|
550
537
|
|
551
538
|
return (task.done ? Qtrue : Qfalse);
|
552
539
|
}
|
553
540
|
|
541
|
+
/*
|
542
|
+
* call-seq:
|
543
|
+
* drop_index(namespace, index_name) -> true or false
|
544
|
+
* drop_index(namespace, index_name, policy_settings) -> true or false
|
545
|
+
*
|
546
|
+
* Remove specified index from node
|
547
|
+
*/
|
554
548
|
VALUE client_drop_index(int argc, VALUE* vArgs, VALUE vSelf)
|
555
549
|
{
|
556
550
|
VALUE vNamespace, vIndexName;
|
@@ -569,8 +563,8 @@ VALUE client_drop_index(int argc, VALUE* vArgs, VALUE vSelf)
|
|
569
563
|
vIndexName = vArgs[1];
|
570
564
|
Check_Type(vIndexName, T_STRING);
|
571
565
|
|
572
|
-
if (argc == 3) {
|
573
|
-
|
566
|
+
if (argc == 3 && TYPE(vArgs[2]) != T_NIL) {
|
567
|
+
SET_INFO_POLICY(policy, vArgs[2]);
|
574
568
|
}
|
575
569
|
|
576
570
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
@@ -583,12 +577,8 @@ VALUE client_drop_index(int argc, VALUE* vArgs, VALUE vSelf)
|
|
583
577
|
}
|
584
578
|
|
585
579
|
bool query_callback(const as_val *value, void *udata) {
|
586
|
-
VALUE vParams[4], vKeyParams[4];
|
587
580
|
VALUE vRecord;
|
588
|
-
|
589
581
|
as_record *record;
|
590
|
-
as_bin bin;
|
591
|
-
int n;
|
592
582
|
|
593
583
|
if (value == NULL) {
|
594
584
|
// query is complete
|
@@ -598,54 +588,36 @@ bool query_callback(const as_val *value, void *udata) {
|
|
598
588
|
record = as_record_fromval(value);
|
599
589
|
|
600
590
|
if (record != NULL) {
|
601
|
-
|
602
|
-
vKeyParams[1] = rb_str_new2(record->key.set);
|
603
|
-
|
604
|
-
if (record->key.valuep == NULL) {
|
605
|
-
vKeyParams[2] = Qnil;
|
606
|
-
} else {
|
607
|
-
vKeyParams[2] = rb_str_new2(record->key.value.string.value);
|
608
|
-
}
|
609
|
-
vKeyParams[3] = rb_str_new(record->key.digest.value, AS_DIGEST_VALUE_SIZE);
|
610
|
-
|
611
|
-
vParams[0] = rb_class_new_instance(4, vKeyParams, KeyClass);
|
612
|
-
vParams[1] = rb_hash_new();
|
613
|
-
vParams[2] = UINT2NUM(record->gen);
|
614
|
-
vParams[3] = UINT2NUM(record->ttl);
|
615
|
-
|
616
|
-
for(n = 0; n < record->bins.size; n++) {
|
617
|
-
bin = record->bins.entries[n];
|
618
|
-
switch( as_val_type(bin.valuep) ) {
|
619
|
-
case AS_INTEGER:
|
620
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
|
621
|
-
break;
|
622
|
-
case AS_STRING:
|
623
|
-
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
624
|
-
break;
|
625
|
-
case AS_UNDEF:
|
626
|
-
default:
|
627
|
-
break;
|
628
|
-
}
|
629
|
-
}
|
630
|
-
|
631
|
-
as_record_destroy(record);
|
632
|
-
vRecord = rb_class_new_instance(4, vParams, RecordClass);
|
591
|
+
vRecord = rb_record_from_c(record, NULL);
|
633
592
|
|
634
593
|
if ( rb_block_given_p() ) {
|
635
594
|
rb_yield(vRecord);
|
636
595
|
} else {
|
637
|
-
|
596
|
+
VALUE *vArray = (VALUE*) udata;
|
597
|
+
rb_ary_push(*vArray, vRecord);
|
638
598
|
}
|
639
599
|
}
|
640
600
|
|
641
601
|
return true;
|
642
602
|
}
|
643
603
|
|
604
|
+
/*
|
605
|
+
* call-seq:
|
606
|
+
* where(namespace, set) -> array
|
607
|
+
* where(namespace, set, conditions) -> array
|
608
|
+
* where(namespace, set, conditions, policy_settings) -> array
|
609
|
+
* where(namespace, set) { |record| ... } -> nil
|
610
|
+
* where(namespace, set, conditions) { |record| ... } -> nil
|
611
|
+
* where(namespace, set, conditions, policy_settings) { |record| ... } -> nil
|
612
|
+
*
|
613
|
+
* Perform a query with where clause
|
614
|
+
*/
|
644
615
|
VALUE client_exec_query(int argc, VALUE* vArgs, VALUE vSelf)
|
645
616
|
{
|
646
617
|
VALUE vNamespace;
|
647
618
|
VALUE vSet;
|
648
619
|
VALUE vConditions;
|
620
|
+
VALUE vArray;
|
649
621
|
|
650
622
|
aerospike *ptr;
|
651
623
|
as_error err;
|
@@ -654,13 +626,8 @@ VALUE client_exec_query(int argc, VALUE* vArgs, VALUE vSelf)
|
|
654
626
|
|
655
627
|
int idx = 0, n = 0;
|
656
628
|
|
657
|
-
if (argc > 4 || argc <
|
658
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for
|
659
|
-
}
|
660
|
-
|
661
|
-
// TODO: write default aggregate block
|
662
|
-
if ( !rb_block_given_p() ) {
|
663
|
-
rb_raise(rb_eArgError, "no block given");
|
629
|
+
if (argc > 4 || argc < 2) { // there should only be 2, 3 or 4 arguments
|
630
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..4)", argc);
|
664
631
|
}
|
665
632
|
|
666
633
|
vNamespace = vArgs[0];
|
@@ -670,18 +637,21 @@ VALUE client_exec_query(int argc, VALUE* vArgs, VALUE vSelf)
|
|
670
637
|
Check_Type(vSet, T_STRING);
|
671
638
|
|
672
639
|
vConditions = vArgs[2];
|
673
|
-
|
640
|
+
switch(TYPE(vConditions)) {
|
641
|
+
case T_NIL:
|
642
|
+
break;
|
643
|
+
case T_ARRAY:
|
644
|
+
idx = RARRAY_LEN(vConditions);
|
645
|
+
break;
|
646
|
+
default:
|
647
|
+
rb_raise(rb_eTypeError, "wrong argument type for condition (expected Array or Nil)");
|
648
|
+
}
|
674
649
|
|
675
650
|
as_policy_query_init(&policy);
|
676
|
-
if (argc == 4) {
|
651
|
+
if (argc == 4 && TYPE(vArgs[3]) != T_NIL) {
|
677
652
|
SET_POLICY(policy, vArgs[3]);
|
678
653
|
}
|
679
654
|
|
680
|
-
idx = RARRAY_LEN(vConditions);
|
681
|
-
if (idx == 0) {
|
682
|
-
return Qnil;
|
683
|
-
}
|
684
|
-
|
685
655
|
Data_Get_Struct(vSelf, aerospike, ptr);
|
686
656
|
|
687
657
|
as_query_init(&query, StringValueCStr(vNamespace), StringValueCStr(vSet));
|
@@ -717,13 +687,18 @@ VALUE client_exec_query(int argc, VALUE* vArgs, VALUE vSelf)
|
|
717
687
|
}
|
718
688
|
}
|
719
689
|
|
720
|
-
|
690
|
+
vArray = rb_ary_new();
|
691
|
+
if (aerospike_query_foreach(ptr, &err, &policy, &query, query_callback, &vArray) != AEROSPIKE_OK) {
|
721
692
|
as_query_destroy(&query);
|
722
693
|
raise_aerospike_exception(err.code, err.message);
|
723
694
|
}
|
724
695
|
as_query_destroy(&query);
|
725
696
|
|
726
|
-
|
697
|
+
if ( rb_block_given_p() ) {
|
698
|
+
return Qnil;
|
699
|
+
}
|
700
|
+
|
701
|
+
return vArray;
|
727
702
|
}
|
728
703
|
|
729
704
|
void define_client()
|
@@ -7,20 +7,163 @@
|
|
7
7
|
VALUE rb_hash_keys(VALUE hash);
|
8
8
|
|
9
9
|
#define SET_POLICY(policy, vSettings) \
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
VALUE vTimeout; \
|
11
|
+
Check_Type(vSettings, T_HASH); \
|
12
|
+
vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout")); \
|
13
|
+
if (TYPE(vTimeout) == T_FIXNUM) { \
|
14
|
+
policy.timeout = NUM2UINT( vTimeout ); \
|
15
|
+
}
|
16
|
+
|
17
|
+
#define SET_RETRY_POLICY(policy, vSettings) \
|
18
|
+
vRetry = rb_hash_aref(vSettings, rb_str_new2("retry")); \
|
19
|
+
if (TYPE(vRetry) == T_FIXNUM) { \
|
20
|
+
int policy_retry = FIX2INT(vRetry); \
|
21
|
+
switch(policy_retry) { \
|
22
|
+
case AS_POLICY_RETRY_NONE: \
|
23
|
+
case AS_POLICY_RETRY_ONCE: \
|
24
|
+
break; \
|
25
|
+
default: \
|
26
|
+
rb_raise(rb_eArgError, "Incorrect \"retry\" policy value"); \
|
27
|
+
} \
|
28
|
+
policy.retry = policy_retry; \
|
29
|
+
}
|
30
|
+
|
31
|
+
#define SET_KEY_POLICY(policy, vSettings) \
|
32
|
+
vKey = rb_hash_aref(vSettings, rb_str_new2("key")); \
|
33
|
+
if (TYPE(vKey) == T_FIXNUM) { \
|
34
|
+
int policy_key = FIX2INT(vKey); \
|
35
|
+
switch(policy_key) { \
|
36
|
+
case AS_POLICY_KEY_DIGEST: \
|
37
|
+
case AS_POLICY_KEY_SEND: \
|
38
|
+
break; \
|
39
|
+
default: \
|
40
|
+
rb_raise(rb_eArgError, "Incorrect \"key\" policy value"); \
|
41
|
+
} \
|
42
|
+
policy.key = policy_key; \
|
43
|
+
}
|
44
|
+
|
45
|
+
#define SET_GEN_POLICY(policy, vSettings) \
|
46
|
+
vGen = rb_hash_aref(vSettings, rb_str_new2("gen")); \
|
47
|
+
if (TYPE(vGen) == T_FIXNUM) { \
|
48
|
+
int policy_gen = FIX2INT(vGen); \
|
49
|
+
switch(policy_gen) { \
|
50
|
+
case AS_POLICY_GEN_IGNORE: \
|
51
|
+
case AS_POLICY_GEN_EQ: \
|
52
|
+
case AS_POLICY_GEN_GT: \
|
53
|
+
break; \
|
54
|
+
default: \
|
55
|
+
rb_raise(rb_eArgError, "Incorrect \"gen\" policy value"); \
|
56
|
+
} \
|
57
|
+
policy.gen = policy_gen; \
|
58
|
+
}
|
59
|
+
|
60
|
+
#define SET_EXISTS_POLICY(policy, vSettings) \
|
61
|
+
vExists = rb_hash_aref(vSettings, rb_str_new2("exists")); \
|
62
|
+
if (TYPE(vExists) == T_FIXNUM) { \
|
63
|
+
int policy_exists = FIX2INT(vExists); \
|
64
|
+
switch(policy_exists) { \
|
65
|
+
case AS_POLICY_EXISTS_CREATE: \
|
66
|
+
case AS_POLICY_EXISTS_CREATE_OR_REPLACE: \
|
67
|
+
case AS_POLICY_EXISTS_IGNORE: \
|
68
|
+
case AS_POLICY_EXISTS_REPLACE: \
|
69
|
+
case AS_POLICY_EXISTS_UPDATE: \
|
70
|
+
break; \
|
71
|
+
default: \
|
72
|
+
rb_raise(rb_eArgError, "Incorrect \"exists\" policy value"); \
|
73
|
+
} \
|
74
|
+
policy.exists = policy_exists; \
|
75
|
+
}
|
76
|
+
|
77
|
+
#define SET_COMMIT_LEVEL_POLICY(policy, vSettings) \
|
78
|
+
vCommitLevel = rb_hash_aref(vSettings, rb_str_new2("commit_level")); \
|
79
|
+
if (TYPE(vCommitLevel) == T_FIXNUM) { \
|
80
|
+
int policy_commit = FIX2INT(vCommitLevel); \
|
81
|
+
switch(policy_commit) { \
|
82
|
+
case AS_POLICY_COMMIT_LEVEL_ALL: \
|
83
|
+
case AS_POLICY_COMMIT_LEVEL_MASTER: \
|
84
|
+
break; \
|
85
|
+
default: \
|
86
|
+
rb_raise(rb_eArgError, "Incorrect \"commit_level\" policy value");\
|
17
87
|
} \
|
18
|
-
|
88
|
+
policy.commit_level = policy_commit; \
|
89
|
+
}
|
90
|
+
|
91
|
+
#define SET_REPLICA_POLICY(policy, vSettings) \
|
92
|
+
vReplica = rb_hash_aref(vSettings, rb_str_new2("replica")); \
|
93
|
+
if (TYPE(vReplica) == T_FIXNUM) { \
|
94
|
+
int policy_replica = FIX2INT(vReplica); \
|
95
|
+
switch(policy_replica) { \
|
96
|
+
case AS_POLICY_REPLICA_ANY: \
|
97
|
+
case AS_POLICY_REPLICA_MASTER: \
|
98
|
+
break; \
|
99
|
+
default: \
|
100
|
+
rb_raise(rb_eArgError, "Incorrect \"replica\" policy value"); \
|
101
|
+
} \
|
102
|
+
policy.replica = policy_replica; \
|
103
|
+
}
|
104
|
+
|
105
|
+
#define SET_CONSISTENCY_LEVEL_POLICY(policy, vSettings) \
|
106
|
+
vConsistencyLevel = rb_hash_aref(vSettings, rb_str_new2("consistency_level")); \
|
107
|
+
if (TYPE(vConsistencyLevel) == T_FIXNUM) { \
|
108
|
+
int policy_consistency_level = FIX2INT(vConsistencyLevel); \
|
109
|
+
switch(policy_consistency_level) { \
|
110
|
+
case AS_POLICY_CONSISTENCY_LEVEL_ALL: \
|
111
|
+
case AS_POLICY_CONSISTENCY_LEVEL_ONE: \
|
112
|
+
break; \
|
113
|
+
default: \
|
114
|
+
rb_raise(rb_eArgError, "Incorrect \"consistency_level\" policy value"); \
|
115
|
+
} \
|
116
|
+
policy.consistency_level = policy_consistency_level; \
|
117
|
+
}
|
118
|
+
|
119
|
+
#define SET_WRITE_POLICY(policy, vSettings) \
|
120
|
+
VALUE vRetry, vKey, vGen, vExists, vCommitLevel; \
|
121
|
+
SET_POLICY(policy, vSettings); \
|
122
|
+
SET_RETRY_POLICY(policy, vSettings); \
|
123
|
+
SET_KEY_POLICY(policy, vSettings); \
|
124
|
+
SET_GEN_POLICY(policy, vSettings); \
|
125
|
+
SET_EXISTS_POLICY(policy, vSettings); \
|
126
|
+
SET_COMMIT_LEVEL_POLICY(policy, vSettings);
|
127
|
+
|
128
|
+
#define SET_READ_POLICY(policy, vSettings) \
|
129
|
+
VALUE vKey, vReplica, vConsistencyLevel; \
|
130
|
+
SET_POLICY(policy, vSettings); \
|
131
|
+
SET_KEY_POLICY(policy, vSettings); \
|
132
|
+
SET_REPLICA_POLICY(policy, vSettings); \
|
133
|
+
SET_CONSISTENCY_LEVEL_POLICY(policy, vSettings);
|
134
|
+
|
135
|
+
#define SET_OPERATE_POLICY(policy, vSettings) \
|
136
|
+
VALUE vRetry, vKey, vGen, vReplica, vConsistencyLevel, vCommitLevel; \
|
137
|
+
SET_POLICY(policy, vSettings); \
|
138
|
+
SET_RETRY_POLICY(policy, vSettings); \
|
139
|
+
SET_KEY_POLICY(policy, vSettings); \
|
140
|
+
SET_GEN_POLICY(policy, vSettings); \
|
141
|
+
SET_REPLICA_POLICY(policy, vSettings); \
|
142
|
+
SET_CONSISTENCY_LEVEL_POLICY(policy, vSettings); \
|
143
|
+
SET_COMMIT_LEVEL_POLICY(policy, vSettings);
|
144
|
+
|
145
|
+
#define SET_REMOVE_POLICY(policy, vSettings) \
|
146
|
+
VALUE vRetry, vKey, vGen, vCommitLevel, vGeneration; \
|
147
|
+
SET_POLICY(policy, vSettings); \
|
148
|
+
SET_RETRY_POLICY(policy, vSettings); \
|
149
|
+
SET_KEY_POLICY(policy, vSettings); \
|
150
|
+
SET_GEN_POLICY(policy, vSettings); \
|
151
|
+
SET_COMMIT_LEVEL_POLICY(policy, vSettings); \
|
152
|
+
vGeneration = rb_hash_aref(vSettings, rb_str_new2("generation")); \
|
153
|
+
if (TYPE(vGeneration) == T_FIXNUM) { \
|
154
|
+
policy.generation = FIX2UINT(vGeneration); \
|
155
|
+
}
|
156
|
+
|
157
|
+
#define SET_INFO_POLICY(policy, vSettings) \
|
158
|
+
VALUE vSendAsIs, vCheckBounds; \
|
159
|
+
SET_POLICY(policy, vSettings); \
|
160
|
+
vSendAsIs = rb_hash_aref(vSettings, rb_str_new2("send_as_is")); \
|
161
|
+
if (TYPE(vSendAsIs) != T_NIL) { \
|
162
|
+
policy.send_as_is = RTEST(vSendAsIs); \
|
19
163
|
} \
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
break; \
|
164
|
+
vCheckBounds = rb_hash_aref(vSettings, rb_str_new2("check_bounds")); \
|
165
|
+
if (TYPE(vCheckBounds) != T_NIL) { \
|
166
|
+
policy.check_bounds = RTEST(vCheckBounds); \
|
24
167
|
}
|
25
168
|
|
26
169
|
#endif // COMMON_H
|
@@ -29,7 +29,7 @@ VALUE condition_initialize(VALUE vSelf, VALUE vBinName, VALUE vIndexType, VALUE
|
|
29
29
|
case T_FIXNUM:
|
30
30
|
break;
|
31
31
|
default:
|
32
|
-
rb_raise(
|
32
|
+
rb_raise(rb_eTypeError, "wrong argument type for max value (expected Fixnum or Nil)");
|
33
33
|
}
|
34
34
|
break;
|
35
35
|
case INDEX_STRING:
|
@@ -39,7 +39,7 @@ VALUE condition_initialize(VALUE vSelf, VALUE vBinName, VALUE vIndexType, VALUE
|
|
39
39
|
case T_STRING:
|
40
40
|
break;
|
41
41
|
default:
|
42
|
-
rb_raise(
|
42
|
+
rb_raise(rb_eTypeError, "wrong argument type for max value (expected String or Nil)");
|
43
43
|
}
|
44
44
|
break;
|
45
45
|
default:
|
@@ -80,7 +80,7 @@ VALUE condition_equal(VALUE vSelf, VALUE vBinName, VALUE vVal)
|
|
80
80
|
index_type = INDEX_STRING;
|
81
81
|
break;
|
82
82
|
default:
|
83
|
-
rb_raise(
|
83
|
+
rb_raise(rb_eTypeError, "wrong argument type for value (expected Fixnum or String)");
|
84
84
|
}
|
85
85
|
|
86
86
|
vArgs[0] = vBinName;
|
data/ext/aerospike_native/key.c
CHANGED
@@ -19,6 +19,13 @@ static VALUE key_allocate(VALUE klass)
|
|
19
19
|
return obj;
|
20
20
|
}
|
21
21
|
|
22
|
+
/*
|
23
|
+
* call-seq:
|
24
|
+
* new(namespace, set, value) -> AerospikeNative::Key
|
25
|
+
* new(namespace, set, value, digest) -> AerospikeNative::Key
|
26
|
+
*
|
27
|
+
* initialize new key
|
28
|
+
*/
|
22
29
|
VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
|
23
30
|
{
|
24
31
|
VALUE vNamespace, vSet, vValue, vDigest = Qnil;
|
@@ -43,7 +50,7 @@ VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
|
|
43
50
|
|
44
51
|
Data_Get_Struct(vSelf, as_key, ptr);
|
45
52
|
|
46
|
-
if(TYPE(
|
53
|
+
if(TYPE(vValue) == T_STRING) {
|
47
54
|
switch(TYPE(vValue)) {
|
48
55
|
case T_FIXNUM:
|
49
56
|
as_key_init_int64(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), FIX2LONG( vValue ));
|
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
VALUE OperationClass;
|
4
4
|
|
5
|
+
/*
|
6
|
+
* call-seq:
|
7
|
+
* new(operation_type, bin_name, bin_value) -> AerospikeNative::Operation
|
8
|
+
*
|
9
|
+
* initialize new operation for client.operate command
|
10
|
+
*/
|
5
11
|
VALUE operation_initialize(VALUE vSelf, VALUE vOpType, VALUE vBinName, VALUE vBinValue)
|
6
12
|
{
|
7
13
|
int op_type = 0;
|
@@ -22,6 +28,12 @@ VALUE operation_initialize(VALUE vSelf, VALUE vOpType, VALUE vBinName, VALUE vBi
|
|
22
28
|
return vSelf;
|
23
29
|
}
|
24
30
|
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* write(bin_name, bin_value) -> AerospikeNative::Operation
|
34
|
+
*
|
35
|
+
* initialize new write operation
|
36
|
+
*/
|
25
37
|
VALUE operation_write(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
26
38
|
{
|
27
39
|
VALUE vArgs[3];
|
@@ -31,6 +43,12 @@ VALUE operation_write(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
|
31
43
|
return rb_class_new_instance(3, vArgs, vSelf);
|
32
44
|
}
|
33
45
|
|
46
|
+
/*
|
47
|
+
* call-seq:
|
48
|
+
* append(bin_name, bin_value) -> AerospikeNative::Operation
|
49
|
+
*
|
50
|
+
* initialize new append operation
|
51
|
+
*/
|
34
52
|
VALUE operation_append(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
35
53
|
{
|
36
54
|
VALUE vArgs[3];
|
@@ -43,6 +61,12 @@ VALUE operation_append(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
|
43
61
|
return rb_class_new_instance(3, vArgs, vSelf);
|
44
62
|
}
|
45
63
|
|
64
|
+
/*
|
65
|
+
* call-seq:
|
66
|
+
* prepend(bin_name, bin_value) -> AerospikeNative::Operation
|
67
|
+
*
|
68
|
+
* initialize new prepend operation
|
69
|
+
*/
|
46
70
|
VALUE operation_prepend(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
47
71
|
{
|
48
72
|
VALUE vArgs[3];
|
@@ -55,6 +79,12 @@ VALUE operation_prepend(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
|
55
79
|
return rb_class_new_instance(3, vArgs, vSelf);
|
56
80
|
}
|
57
81
|
|
82
|
+
/*
|
83
|
+
* call-seq:
|
84
|
+
* increment(bin_name, bin_value) -> AerospikeNative::Operation
|
85
|
+
*
|
86
|
+
* initialize new increment operation
|
87
|
+
*/
|
58
88
|
VALUE operation_increment(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
59
89
|
{
|
60
90
|
VALUE vArgs[3];
|
@@ -67,6 +97,12 @@ VALUE operation_increment(VALUE vSelf, VALUE vBinName, VALUE vBinValue)
|
|
67
97
|
return rb_class_new_instance(3, vArgs, vSelf);
|
68
98
|
}
|
69
99
|
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* touch() -> AerospikeNative::Operation
|
103
|
+
*
|
104
|
+
* initialize new touch operation
|
105
|
+
*/
|
70
106
|
VALUE operation_touch(VALUE vSelf)
|
71
107
|
{
|
72
108
|
VALUE vArgs[3];
|
@@ -77,6 +113,12 @@ VALUE operation_touch(VALUE vSelf)
|
|
77
113
|
return rb_class_new_instance(3, vArgs, vSelf);
|
78
114
|
}
|
79
115
|
|
116
|
+
/*
|
117
|
+
* call-seq:
|
118
|
+
* read(bin_name) -> AerospikeNative::Operation
|
119
|
+
*
|
120
|
+
* initialize new read operation
|
121
|
+
*/
|
80
122
|
VALUE operation_read(VALUE vSelf, VALUE vBinName)
|
81
123
|
{
|
82
124
|
VALUE vArgs[3];
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#include "policy.h"
|
2
|
+
#include <aerospike/as_policy.h>
|
3
|
+
|
4
|
+
VALUE PolicyClass;
|
5
|
+
|
6
|
+
void define_policy()
|
7
|
+
{
|
8
|
+
PolicyClass = rb_define_class_under(AerospikeNativeClass, "Policy", rb_cObject);
|
9
|
+
|
10
|
+
rb_define_const(PolicyClass, "RETRY_NONE", INT2FIX(AS_POLICY_RETRY_NONE));
|
11
|
+
rb_define_const(PolicyClass, "RETRY_ONCE", INT2FIX(AS_POLICY_RETRY_ONCE));
|
12
|
+
|
13
|
+
rb_define_const(PolicyClass, "KEY_DIGEST", INT2FIX(AS_POLICY_KEY_DIGEST));
|
14
|
+
rb_define_const(PolicyClass, "KEY_SEND", INT2FIX(AS_POLICY_KEY_SEND));
|
15
|
+
|
16
|
+
rb_define_const(PolicyClass, "GEN_IGNORE", INT2FIX(AS_POLICY_GEN_IGNORE));
|
17
|
+
rb_define_const(PolicyClass, "GEN_EQ", INT2FIX(AS_POLICY_GEN_EQ));
|
18
|
+
rb_define_const(PolicyClass, "GEN_GT", INT2FIX(AS_POLICY_GEN_GT));
|
19
|
+
|
20
|
+
rb_define_const(PolicyClass, "EXISTS_CREATE", INT2FIX(AS_POLICY_EXISTS_CREATE));
|
21
|
+
rb_define_const(PolicyClass, "EXISTS_CREATE_OR_REPLACE", INT2FIX(AS_POLICY_EXISTS_CREATE_OR_REPLACE));
|
22
|
+
rb_define_const(PolicyClass, "EXISTS_IGNORE", INT2FIX(AS_POLICY_EXISTS_IGNORE));
|
23
|
+
rb_define_const(PolicyClass, "EXISTS_REPLACE", INT2FIX(AS_POLICY_EXISTS_REPLACE));
|
24
|
+
rb_define_const(PolicyClass, "EXISTS_UPDATE", INT2FIX(AS_POLICY_EXISTS_UPDATE));
|
25
|
+
|
26
|
+
rb_define_const(PolicyClass, "COMMIT_LEVEL_ALL", INT2FIX(AS_POLICY_COMMIT_LEVEL_ALL));
|
27
|
+
rb_define_const(PolicyClass, "COMMIT_LEVEL_MASTER", INT2FIX(AS_POLICY_COMMIT_LEVEL_MASTER));
|
28
|
+
|
29
|
+
rb_define_const(PolicyClass, "REPLICA_ANY", INT2FIX(AS_POLICY_REPLICA_ANY));
|
30
|
+
rb_define_const(PolicyClass, "REPLICA_MASTER", INT2FIX(AS_POLICY_REPLICA_MASTER));
|
31
|
+
|
32
|
+
rb_define_const(PolicyClass, "CONSISTENCY_LEVEL_ALL", INT2FIX(AS_POLICY_CONSISTENCY_LEVEL_ALL));
|
33
|
+
rb_define_const(PolicyClass, "CONSISTENCY_LEVEL_ONE", INT2FIX(AS_POLICY_CONSISTENCY_LEVEL_ONE));
|
34
|
+
}
|
@@ -3,6 +3,12 @@
|
|
3
3
|
|
4
4
|
VALUE RecordClass;
|
5
5
|
|
6
|
+
/*
|
7
|
+
* call-seq:
|
8
|
+
* new(key, bins, gen, ttl) -> AerospikeNative::Record
|
9
|
+
*
|
10
|
+
* initialize new record
|
11
|
+
*/
|
6
12
|
VALUE record_initialize(VALUE vSelf, VALUE vKey, VALUE vBins, VALUE vGen, VALUE vTtl)
|
7
13
|
{
|
8
14
|
check_aerospike_key(vKey);
|
@@ -18,6 +24,52 @@ VALUE record_initialize(VALUE vSelf, VALUE vKey, VALUE vBins, VALUE vGen, VALUE
|
|
18
24
|
return vSelf;
|
19
25
|
}
|
20
26
|
|
27
|
+
VALUE rb_record_from_c(as_record* record, as_key* key)
|
28
|
+
{
|
29
|
+
VALUE vKeyParams[5], vParams[4];
|
30
|
+
as_key current_key;
|
31
|
+
as_bin bin;
|
32
|
+
int n;
|
33
|
+
|
34
|
+
if (key == NULL) {
|
35
|
+
current_key = record->key;
|
36
|
+
} else {
|
37
|
+
current_key = *key;
|
38
|
+
}
|
39
|
+
|
40
|
+
vKeyParams[0] = rb_str_new2(current_key.ns);
|
41
|
+
vKeyParams[1] = rb_str_new2(current_key.set);
|
42
|
+
|
43
|
+
if (current_key.valuep == NULL) {
|
44
|
+
vKeyParams[2] = Qnil;
|
45
|
+
} else {
|
46
|
+
vKeyParams[2] = rb_str_new2(current_key.value.string.value);
|
47
|
+
}
|
48
|
+
vKeyParams[3] = rb_str_new(current_key.digest.value, AS_DIGEST_VALUE_SIZE);
|
49
|
+
|
50
|
+
vParams[0] = rb_class_new_instance(4, vKeyParams, KeyClass);
|
51
|
+
vParams[1] = rb_hash_new();
|
52
|
+
vParams[2] = UINT2NUM(record->gen);
|
53
|
+
vParams[3] = UINT2NUM(record->ttl);
|
54
|
+
|
55
|
+
for(n = 0; n < record->bins.size; n++) {
|
56
|
+
bin = record->bins.entries[n];
|
57
|
+
switch( as_val_type(bin.valuep) ) {
|
58
|
+
case AS_INTEGER:
|
59
|
+
rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
|
60
|
+
break;
|
61
|
+
case AS_STRING:
|
62
|
+
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
63
|
+
break;
|
64
|
+
case AS_UNDEF:
|
65
|
+
default:
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
as_record_destroy(record);
|
71
|
+
return rb_class_new_instance(4, vParams, RecordClass);
|
72
|
+
}
|
21
73
|
|
22
74
|
void define_record()
|
23
75
|
{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aerospike_native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Ziablitskii
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- ext/aerospike_native/lib/.keep
|
98
98
|
- ext/aerospike_native/operation.c
|
99
99
|
- ext/aerospike_native/operation.h
|
100
|
+
- ext/aerospike_native/policy.c
|
101
|
+
- ext/aerospike_native/policy.h
|
100
102
|
- ext/aerospike_native/record.c
|
101
103
|
- ext/aerospike_native/record.h
|
102
104
|
- lib/aerospike_native.rb
|