aerospike_native 0.2.0 → 0.2.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 +7 -2
- data/aerospike_native.gemspec +2 -0
- data/examples/common/common.rb +38 -0
- data/examples/operate.rb +31 -0
- data/examples/query_and_index.rb +19 -0
- data/ext/aerospike_native/client.c +30 -9
- data/ext/aerospike_native/record.c +7 -0
- data/lib/aerospike_native.rb +1 -0
- data/lib/aerospike_native/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ac94d9b34b064822cc15dd0976ed7ced4b76c27
|
4
|
+
data.tar.gz: 085fe5f23cb779c0ff29a7cb74d82ecef51de905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e3ce1b3fb8a94c61a88bb839790769f1f9112abc1ed7526c464e1c9cfb1195b13d8e4c0bdb40fa09d84c3dab6b289cc119f0f95b53d4f58b463409b2e18a9a
|
7
|
+
data.tar.gz: 9384e2914162cbcc79aa1bb0e2bd850685e158c0617c59c0b8ab338da4d50782a794715779a69d113b8fc13ccb1d55c835593813fedc2b9752d67b7a3545a27f
|
data/README.md
CHANGED
@@ -26,13 +26,18 @@ Or install it yourself as:
|
|
26
26
|
* `remove` command
|
27
27
|
* `select` command
|
28
28
|
* `exixts?` command
|
29
|
-
* `
|
30
|
-
*
|
29
|
+
* `query` command (where and select support)
|
30
|
+
* Supported bytes type for non-native object types(string or fixnum) via [msgpack](https://github.com/msgpack/msgpack-ruby)
|
31
|
+
* lists and maps for bin value not supported yet (stored as bytes at the moment)
|
31
32
|
* Supported policies with all parameters for described commands
|
32
33
|
* Supported digest keys
|
33
34
|
* Supported exceptions (`AerospikeNative::Exception`) with several error codes constants `AerospikeNative::Exception.constants`
|
34
35
|
* Index management (`create_index` and `drop_index`)
|
35
36
|
|
37
|
+
## Examples
|
38
|
+
|
39
|
+
In path `examples`
|
40
|
+
|
36
41
|
## Usage
|
37
42
|
|
38
43
|
### Basic
|
data/aerospike_native.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ["lib", "ext"]
|
22
22
|
spec.extensions = %w[ext/aerospike_native/extconf.rb]
|
23
23
|
|
24
|
+
spec.add_dependency "msgpack", "~> 0.6"
|
25
|
+
|
24
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
28
|
spec.add_development_dependency "rake-compiler", "~> 0.9"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'aerospike_native'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Common
|
5
|
+
class Common
|
6
|
+
class << self
|
7
|
+
def namespace; 'test' end
|
8
|
+
def set; 'examples' end
|
9
|
+
def client; @@client ||= AerospikeNative::Client.new([{'host' => '127.0.0.1', 'port' => 3010}]) end
|
10
|
+
|
11
|
+
def cleanup
|
12
|
+
client.query(namespace, set).exec{ |record| client.remove(record.key) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def custom_logger
|
16
|
+
@@logger = Logger.new(STDOUT, Logger::DEBUG)
|
17
|
+
end
|
18
|
+
|
19
|
+
def set_custom_logger
|
20
|
+
AerospikeNative::Client.set_logger custom_logger
|
21
|
+
AerospikeNative::Client.set_log_level :debug
|
22
|
+
end
|
23
|
+
|
24
|
+
def init
|
25
|
+
set_custom_logger
|
26
|
+
client
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_example
|
30
|
+
init
|
31
|
+
custom_logger.info "Example started"
|
32
|
+
yield(client, namespace, set, custom_logger)
|
33
|
+
cleanup
|
34
|
+
custom_logger.info "Example finished"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/examples/operate.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require './common/common'
|
2
|
+
|
3
|
+
def main
|
4
|
+
Common::Common.run_example do |client, namespace, set, logger|
|
5
|
+
key = AerospikeNative::Key.new(namespace, set, "operate_test")
|
6
|
+
bins = []
|
7
|
+
bins << AerospikeNative::Operation.write('value', 'beep')
|
8
|
+
bins << AerospikeNative::Operation.write('incr', 5)
|
9
|
+
|
10
|
+
record = client.operate(key, bins)
|
11
|
+
logger.info "Without read or touch: #{record.inspect}"
|
12
|
+
|
13
|
+
bins = []
|
14
|
+
bins << AerospikeNative::Operation.touch
|
15
|
+
bins << AerospikeNative::Operation.append('value', '_once')
|
16
|
+
bins << AerospikeNative::Operation.increment('incr', 10)
|
17
|
+
|
18
|
+
record = client.operate(key, bins)
|
19
|
+
logger.info "With touch: #{record.inspect}"
|
20
|
+
|
21
|
+
bins = []
|
22
|
+
bins << AerospikeNative::Operation.read('value')
|
23
|
+
bins << AerospikeNative::Operation.read('incr')
|
24
|
+
bins << AerospikeNative::Operation.prepend('value', 'twice_')
|
25
|
+
|
26
|
+
record = client.operate(key, bins)
|
27
|
+
logger.info "With read: #{record.inspect}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
main
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require './common/common'
|
2
|
+
|
3
|
+
def main
|
4
|
+
Common::Common.run_example do |client, namespace, set, logger|
|
5
|
+
index_name = "number_#{set}_idx"
|
6
|
+
client.create_index(namespace, set, 'number', index_name)
|
7
|
+
|
8
|
+
20.times do |i|
|
9
|
+
client.put(AerospikeNative::Key.new(namespace, set, i), {'number' => i, 'key' => 'number', 'testbin' => i.to_s})
|
10
|
+
end
|
11
|
+
|
12
|
+
records = client.query(namespace, set).select(:number, :testbin).where(number: [10, 15]).exec
|
13
|
+
logger.info records.inspect
|
14
|
+
|
15
|
+
client.drop_index(namespace, index_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
main
|
@@ -78,10 +78,17 @@ VALUE client_initialize(int argc, VALUE* argv, VALUE self)
|
|
78
78
|
if (TYPE(ary) == T_ARRAY) {
|
79
79
|
idx = RARRAY_LEN(ary);
|
80
80
|
for(n = 0; n < idx; n++) {
|
81
|
+
VALUE vHost, vPort;
|
81
82
|
VALUE hash = rb_ary_entry(ary, n);
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
vHost = rb_hash_aref(hash, rb_str_new2("host"));
|
84
|
+
if (TYPE(vHost) == T_NIL) {
|
85
|
+
vHost = rb_hash_aref(hash, ID2SYM( rb_intern("host") ));
|
86
|
+
}
|
87
|
+
vPort = rb_hash_aref(hash, rb_str_new2("port"));
|
88
|
+
if (TYPE(vPort) == T_NIL) {
|
89
|
+
vPort = rb_hash_aref(hash, ID2SYM( rb_intern("port") ));
|
90
|
+
}
|
91
|
+
as_config_add_host(&config, StringValueCStr(vHost), NUM2UINT(vPort));
|
85
92
|
}
|
86
93
|
}
|
87
94
|
|
@@ -159,10 +166,17 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
|
|
159
166
|
case T_FIXNUM:
|
160
167
|
as_record_set_int64(&record, StringValueCStr(bin_name), NUM2LONG(bin_value));
|
161
168
|
break;
|
162
|
-
|
163
|
-
|
169
|
+
// case T_ARRAY:
|
170
|
+
// case T_HASH:
|
171
|
+
// rb_raise(rb_eTypeError, "wrong argument type for bin value (hashes and arrays not supported yet)");
|
172
|
+
// break;
|
173
|
+
default: {
|
174
|
+
VALUE vBytes = rb_funcall(bin_value, rb_intern("to_msgpack"), 0);
|
175
|
+
int strSize = RSTRING_LEN(vBytes);
|
176
|
+
as_record_set_raw(&record, StringValueCStr(bin_name), StringValuePtr(vBytes), strSize);
|
164
177
|
break;
|
165
178
|
}
|
179
|
+
}
|
166
180
|
}
|
167
181
|
|
168
182
|
Data_Get_Struct(vKey, as_key, key);
|
@@ -285,10 +299,17 @@ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
|
|
285
299
|
case T_FIXNUM:
|
286
300
|
as_operations_add_write_int64(&ops, StringValueCStr( bin_name ), NUM2LONG( bin_value ));
|
287
301
|
break;
|
288
|
-
|
289
|
-
|
302
|
+
// case T_ARRAY:
|
303
|
+
// case T_HASH:
|
304
|
+
// rb_raise(rb_eTypeError, "wrong argument type for bin value (hashes and arrays not supported yet)");
|
305
|
+
// break;
|
306
|
+
default: {
|
307
|
+
VALUE vBytes = rb_funcall(bin_value, rb_intern("to_msgpack"), 0);
|
308
|
+
int strSize = RSTRING_LEN(vBytes);
|
309
|
+
as_operations_add_write_raw(&ops, StringValueCStr(bin_name), StringValuePtr(vBytes), strSize);
|
290
310
|
break;
|
291
311
|
}
|
312
|
+
}
|
292
313
|
|
293
314
|
break;
|
294
315
|
case OPERATION_READ:
|
@@ -602,9 +623,9 @@ VALUE client_drop_index(int argc, VALUE* vArgs, VALUE vSelf)
|
|
602
623
|
|
603
624
|
/*
|
604
625
|
* call-seq:
|
605
|
-
*
|
626
|
+
* query(namespace, set) -> AerospikeNative::Query
|
606
627
|
*
|
607
|
-
*
|
628
|
+
* Instantiate new query
|
608
629
|
*/
|
609
630
|
VALUE client_query(VALUE vSelf, VALUE vNamespace, VALUE vSet)
|
610
631
|
{
|
@@ -29,6 +29,7 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
|
|
29
29
|
{
|
30
30
|
VALUE vKeyParams[5], vParams[4];
|
31
31
|
VALUE vLogger;
|
32
|
+
VALUE vMsgPackClass;
|
32
33
|
as_key current_key;
|
33
34
|
as_bin bin;
|
34
35
|
int n;
|
@@ -60,6 +61,7 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
|
|
60
61
|
vParams[2] = UINT2NUM(record->gen);
|
61
62
|
vParams[3] = UINT2NUM(record->ttl);
|
62
63
|
|
64
|
+
vMsgPackClass = rb_const_get(rb_cObject, rb_intern("MessagePack"));
|
63
65
|
for(n = 0; n < record->bins.size; n++) {
|
64
66
|
bin = record->bins.entries[n];
|
65
67
|
switch( as_val_type(bin.valuep) ) {
|
@@ -72,6 +74,11 @@ VALUE rb_record_from_c(as_record* record, as_key* key)
|
|
72
74
|
case AS_STRING:
|
73
75
|
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
|
74
76
|
break;
|
77
|
+
case AS_BYTES: {
|
78
|
+
VALUE vString = rb_str_new(bin.valuep->bytes.value, bin.valuep->bytes.size);
|
79
|
+
rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_funcall(vMsgPackClass, rb_intern("unpack"), 1, vString));
|
80
|
+
break;
|
81
|
+
}
|
75
82
|
case AS_UNDEF:
|
76
83
|
default:
|
77
84
|
vLogger = rb_cv_get(ClientClass, "@@logger");
|
data/lib/aerospike_native.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aerospike_native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: msgpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +95,9 @@ files:
|
|
81
95
|
- README.md
|
82
96
|
- Rakefile
|
83
97
|
- aerospike_native.gemspec
|
98
|
+
- examples/common/common.rb
|
99
|
+
- examples/operate.rb
|
100
|
+
- examples/query_and_index.rb
|
84
101
|
- ext/aerospike_native/aerospike_native.c
|
85
102
|
- ext/aerospike_native/aerospike_native.h
|
86
103
|
- ext/aerospike_native/client.c
|