actsasflinn-ruby-tokyotyrant 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/ext/tokyo_tyrant_db.c +3 -7
- data/ext/tokyo_tyrant_module.c +15 -3
- data/ext/tokyo_tyrant_query.c +9 -5
- data/ext/tokyo_tyrant_table.c +12 -2
- data/spec/tokyo_tyrant_query_spec.rb +13 -4
- data/spec/tokyo_tyrant_spec.rb +5 -1
- data/spec/tokyo_tyrant_table_spec.rb +5 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@ This is a c extension for Ruby to access TokyoTyrant databases. It currently su
|
|
4
4
|
|
5
5
|
== Install
|
6
6
|
|
7
|
-
# install
|
7
|
+
# install tokyocabinet and tokyotyrant (requires 1.1.27)
|
8
8
|
# after installing tc and tt on linux I had to /sbin/ldconfig (as root)
|
9
9
|
gem sources -a http://gems.github.com
|
10
10
|
sudo gem install actsasflinn-ruby-tokyotyrant
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ CLEAN.include('pkg', 'tmp')
|
|
20
20
|
|
21
21
|
gemspec = Gem::Specification.new do |s|
|
22
22
|
s.name = 'ruby-tokyotyrant'
|
23
|
-
s.version = '0.1.
|
23
|
+
s.version = '0.1.7'
|
24
24
|
s.authors = [ 'Flinn' ]
|
25
25
|
s.email = 'flinn@actsasflinn.com'
|
26
26
|
s.homepage = 'http://github.com/actsasflinn/ruby-tokyotyrant/'
|
data/ext/tokyo_tyrant_db.c
CHANGED
@@ -81,17 +81,13 @@ static VALUE cDB_putshl(VALUE vself, VALUE vkey, VALUE vstr, VALUE vwidth){
|
|
81
81
|
return Qtrue;
|
82
82
|
}
|
83
83
|
|
84
|
-
static VALUE cDB_get(
|
85
|
-
VALUE
|
84
|
+
static VALUE cDB_get(VALUE vself, VALUE vkey){
|
85
|
+
VALUE vval;
|
86
86
|
char *buf;
|
87
87
|
int bsiz, ecode;
|
88
|
-
bool raw;
|
89
88
|
TCRDB *db;
|
90
89
|
Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
|
91
90
|
|
92
|
-
rb_scan_args(argc, argv, "11", &vkey, &vraw);
|
93
|
-
raw = (vraw == Qtrue);
|
94
|
-
|
95
91
|
// this is ugly
|
96
92
|
vkey = StringValueEx(vkey);
|
97
93
|
if(!(buf = tcrdbget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey), &bsiz))){
|
@@ -231,7 +227,7 @@ void init_db(){
|
|
231
227
|
rb_define_method(cDB, "putcat", cDB_putcat, 2);
|
232
228
|
rb_define_method(cDB, "putshl", cDB_putshl, 2);
|
233
229
|
rb_define_method(cDB, "putnr", cDB_putnr, 2);
|
234
|
-
rb_define_method(cDB, "get", cDB_get,
|
230
|
+
rb_define_method(cDB, "get", cDB_get, 1);
|
235
231
|
rb_define_alias(cDB, "[]", "get");
|
236
232
|
rb_define_method(cDB, "mget", cDB_mget, -1);
|
237
233
|
rb_define_alias(cDB, "lget", "mget"); // Rufus Compat
|
data/ext/tokyo_tyrant_module.c
CHANGED
@@ -4,6 +4,10 @@ static void mTokyoTyrant_free(TCRDB *db){
|
|
4
4
|
tcrdbdel(db);
|
5
5
|
}
|
6
6
|
|
7
|
+
static VALUE mTokyoTyrant_server(VALUE vself){
|
8
|
+
return rb_iv_get(vself, "@server");;
|
9
|
+
}
|
10
|
+
|
7
11
|
static VALUE mTokyoTyrant_close(VALUE vself){
|
8
12
|
int ecode;
|
9
13
|
TCRDB *db;
|
@@ -17,23 +21,30 @@ static VALUE mTokyoTyrant_close(VALUE vself){
|
|
17
21
|
}
|
18
22
|
|
19
23
|
static VALUE mTokyoTyrant_initialize(int argc, VALUE *argv, VALUE vself){
|
20
|
-
VALUE host, port;
|
24
|
+
VALUE host, port, timeout, retry, server;
|
21
25
|
int ecode;
|
22
26
|
TCRDB *db;
|
23
27
|
|
24
|
-
rb_scan_args(argc, argv, "
|
28
|
+
rb_scan_args(argc, argv, "04", &host, &port, &timeout, &retry);
|
25
29
|
if(NIL_P(host)) host = rb_str_new2("127.0.0.1");
|
26
30
|
if(NIL_P(port)) port = INT2FIX(1978);
|
31
|
+
if(NIL_P(timeout)) timeout = rb_float_new(0.0);
|
32
|
+
if(NIL_P(retry)) retry = Qfalse;
|
27
33
|
|
28
34
|
db = tcrdbnew();
|
29
35
|
|
30
|
-
if(!
|
36
|
+
if((!tcrdbtune(db, timeout, retry == Qtrue ? RDBTRECON : 0)) ||
|
37
|
+
(!tcrdbopen(db, RSTRING_PTR(host), FIX2INT(port)))){
|
31
38
|
ecode = tcrdbecode(db);
|
32
39
|
rb_raise(eTokyoTyrantError, "open error: %s", tcrdberrmsg(ecode));
|
33
40
|
}
|
34
41
|
|
42
|
+
server = rb_str_new2(tcrdbexpr(db));
|
43
|
+
rb_iv_set(vself, "@server", server);
|
35
44
|
rb_iv_set(vself, "@host", host);
|
36
45
|
rb_iv_set(vself, "@port", port);
|
46
|
+
rb_iv_set(vself, "@timeout", timeout);
|
47
|
+
rb_iv_set(vself, "@retry", retry);
|
37
48
|
rb_iv_set(vself, RDBVNDATA, Data_Wrap_Struct(rb_cObject, 0, mTokyoTyrant_free, db));
|
38
49
|
|
39
50
|
return Qtrue;
|
@@ -336,6 +347,7 @@ void init_mod(){
|
|
336
347
|
rb_define_const(mTokyoTyrant, "ITKEEP", INT2NUM(RDBITKEEP));
|
337
348
|
|
338
349
|
rb_define_private_method(mTokyoTyrant, "initialize", mTokyoTyrant_initialize, -1);
|
350
|
+
rb_define_method(mTokyoTyrant, "server", mTokyoTyrant_server, 0);
|
339
351
|
rb_define_method(mTokyoTyrant, "close", mTokyoTyrant_close, 0);
|
340
352
|
rb_define_method(mTokyoTyrant, "errmsg", mTokyoTyrant_errmsg, -1);
|
341
353
|
rb_define_method(mTokyoTyrant, "ecode", mTokyoTyrant_ecode, 0);
|
data/ext/tokyo_tyrant_query.c
CHANGED
@@ -53,12 +53,15 @@ static VALUE cQuery_setorder(VALUE vself, VALUE vname, VALUE vtype){
|
|
53
53
|
return vself;
|
54
54
|
}
|
55
55
|
|
56
|
-
static VALUE
|
57
|
-
VALUE vqry;
|
56
|
+
static VALUE cQuery_setlimit(int argc, VALUE *argv, VALUE vself){
|
57
|
+
VALUE vqry, vmax, vskip;
|
58
58
|
RDBQRY *qry;
|
59
59
|
vqry = rb_iv_get(vself, RDBQRYVNDATA);
|
60
60
|
Data_Get_Struct(vqry, RDBQRY, qry);
|
61
|
-
|
61
|
+
rb_scan_args(argc, argv, "11", &vmax, &vskip);
|
62
|
+
if(NIL_P(vskip)) vskip = INT2FIX(0);
|
63
|
+
|
64
|
+
tcrdbqrysetlimit(qry, NUM2INT(vmax), NUM2INT(vskip));
|
62
65
|
return vself;
|
63
66
|
}
|
64
67
|
|
@@ -157,8 +160,9 @@ void init_query(){
|
|
157
160
|
rb_define_alias(cQuery, "add", "addcond"); // Rufus Compat
|
158
161
|
rb_define_method(cQuery, "setorder", cQuery_setorder, 2);
|
159
162
|
rb_define_alias(cQuery, "order_by", "setorder"); // Rufus Compat
|
160
|
-
rb_define_method(cQuery, "
|
161
|
-
rb_define_alias(cQuery, "
|
163
|
+
rb_define_method(cQuery, "setlimit", cQuery_setlimit, -1);
|
164
|
+
rb_define_alias(cQuery, "setmax", "setlimit"); // Rufus Compat
|
165
|
+
rb_define_alias(cQuery, "limit", "setlimit"); // Rufus Compat
|
162
166
|
rb_define_method(cQuery, "search", cQuery_search, 0);
|
163
167
|
rb_define_alias(cQuery, "run", "search");
|
164
168
|
rb_define_method(cQuery, "searchout", cQuery_searchout, 0);
|
data/ext/tokyo_tyrant_table.c
CHANGED
@@ -95,13 +95,23 @@ static VALUE cTable_out(VALUE vself, VALUE vkey){
|
|
95
95
|
|
96
96
|
static VALUE cTable_get(VALUE vself, VALUE vkey){
|
97
97
|
VALUE vcols;
|
98
|
+
int ecode;
|
98
99
|
TCRDB *db;
|
99
100
|
TCMAP *cols;
|
100
101
|
Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
|
102
|
+
|
101
103
|
vkey = StringValueEx(vkey);
|
104
|
+
if(!(cols = tcrdbtblget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey)))){
|
105
|
+
if ((ecode = tcrdbecode(db))) {
|
106
|
+
if (ecode != TTENOREC) {
|
107
|
+
rb_raise(eTokyoTyrantError, "get error: %s", tcrdberrmsg(ecode));
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return Qnil;
|
111
|
+
} else {
|
112
|
+
vcols = maptovhashsym(cols);
|
113
|
+
}
|
102
114
|
|
103
|
-
if(!(cols = tcrdbtblget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey)))) return Qnil;
|
104
|
-
vcols = maptovhashsym(cols);
|
105
115
|
tcmapdel(cols);
|
106
116
|
return vcols;
|
107
117
|
}
|
@@ -41,10 +41,19 @@ describe TokyoTyrant::Query, "with an open database" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should get limited keys for search conditions with limit" do
|
44
|
-
q = @db.query
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
q = @db.query{ |q|
|
45
|
+
q.addcond('type', :streq, 'Apple')
|
46
|
+
q.order_by('variety', :strdesc)
|
47
|
+
q.setlimit(10)
|
48
|
+
}.should == ["4860", "3011", "3271", "3382", "4182", "3353", "4176", "3272", "3297", "3009"]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should get limited keys for search conditions with limit and offset" do
|
52
|
+
q = @db.query{ |q|
|
53
|
+
q.addcond('type', :streq, 'Apple')
|
54
|
+
q.order_by('variety', :strdesc)
|
55
|
+
q.setlimit(10, 10)
|
56
|
+
}.should == ["3008", "3352", "3077", "3349", "3076", "3073", "3348", "3007", "3078", "3347"]
|
48
57
|
end
|
49
58
|
|
50
59
|
it "should get records for search conditions" do
|
data/spec/tokyo_tyrant_spec.rb
CHANGED
@@ -21,6 +21,10 @@ describe TokyoTyrant::DB, "with an open database" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should return a server expression" do
|
25
|
+
@db.server.should == '127.0.0.1:45000'
|
26
|
+
end
|
27
|
+
|
24
28
|
it "should save a value" do
|
25
29
|
@db[:salad] = 'bacon bits'
|
26
30
|
@db[:salad].should == 'bacon bits'
|
@@ -152,7 +156,7 @@ describe TokyoTyrant::DB, "with an open database" do
|
|
152
156
|
|
153
157
|
it "should report db size" do
|
154
158
|
@db['rootbeer'] = 'virgils'
|
155
|
-
@db.db_size.should ==
|
159
|
+
@db.db_size.should.not == 0
|
156
160
|
end
|
157
161
|
|
158
162
|
it "should fetch a record" do
|
@@ -21,6 +21,10 @@ describe TokyoTyrant::Table, "with an open database" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
it "should return a server expression" do
|
25
|
+
@db.server.should == '127.0.0.1:45001'
|
26
|
+
end
|
27
|
+
|
24
28
|
it "should save a value" do
|
25
29
|
value = { :lettuce => 'Red Leaf', :dressing => 'ranch', :extra => 'bacon bits' }
|
26
30
|
@db[:salad] = value
|
@@ -156,7 +160,7 @@ describe TokyoTyrant::Table, "with an open database" do
|
|
156
160
|
|
157
161
|
it "should report db size" do
|
158
162
|
@db['rootbeer'] = { :gourmet => 'Virgils', :natural => 'Hansens' }
|
159
|
-
@db.db_size.should ==
|
163
|
+
@db.db_size.should.not == 0
|
160
164
|
end
|
161
165
|
|
162
166
|
it "should fetch a record" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actsasflinn-ruby-tokyotyrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flinn
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|