metry 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +14 -69
- data/TODO +2 -3
- data/cucumber.yml +1 -0
- data/example/example.rb +1 -1
- data/features/psycho/dashboard.feature +17 -0
- data/features/psycho/goals.feature +24 -0
- data/features/psycho/visitor_tracking.feature +32 -0
- data/features/step_definitions/goals.rb +3 -0
- data/features/step_definitions/tracking.rb +1 -1
- data/features/step_definitions/web.rb +14 -2
- data/features/support/env.rb +4 -0
- data/lib/metry.rb +4 -6
- data/lib/metry/experiment.rb +6 -8
- data/lib/metry/psycho.rb +112 -0
- data/lib/metry/psycho/dashboard.erb +14 -0
- data/lib/metry/psycho/layout.erb +8 -0
- data/lib/metry/psycho/new_goal.erb +9 -0
- data/lib/metry/psycho/visitor.erb +7 -0
- data/lib/metry/rack/tracking.rb +17 -13
- data/lib/metry/storage.rb +116 -0
- data/radiant/example/features/metry.feature +8 -8
- data/radiant/example/features/psycho.feature +13 -0
- data/radiant/example/features/step_definitions/experiments.rb +2 -2
- data/radiant/example/features/step_definitions/tracking.rb +1 -1
- data/radiant/example/features/support/env.rb +3 -0
- data/radiant/extension/lib/metry_authenticator.rb +30 -0
- data/radiant/extension/lib/metry_tags.rb +2 -1
- data/radiant/extension/metry_extension.rb +1 -1
- data/test/{test_tokyo.rb → test_storage.rb} +3 -3
- metadata +17 -72
- data/lib/metry/memory.rb +0 -27
- data/lib/metry/tokyo.rb +0 -181
- data/vendor/rufus-tokyo/CHANGELOG.txt +0 -112
- data/vendor/rufus-tokyo/CREDITS.txt +0 -27
- data/vendor/rufus-tokyo/LICENSE.txt +0 -21
- data/vendor/rufus-tokyo/README.txt +0 -310
- data/vendor/rufus-tokyo/Rakefile +0 -118
- data/vendor/rufus-tokyo/TODO.txt +0 -25
- data/vendor/rufus-tokyo/doc/decision_table.numbers +0 -0
- data/vendor/rufus-tokyo/doc/rdoc-style.css +0 -320
- data/vendor/rufus-tokyo/lib/rufus-edo.rb +0 -3
- data/vendor/rufus-tokyo/lib/rufus-tokyo.rb +0 -3
- data/vendor/rufus-tokyo/lib/rufus/edo.rb +0 -39
- data/vendor/rufus-tokyo/lib/rufus/edo/README.txt +0 -106
- data/vendor/rufus-tokyo/lib/rufus/edo/cabcore.rb +0 -333
- data/vendor/rufus-tokyo/lib/rufus/edo/cabinet/abstract.rb +0 -219
- data/vendor/rufus-tokyo/lib/rufus/edo/cabinet/table.rb +0 -159
- data/vendor/rufus-tokyo/lib/rufus/edo/error.rb +0 -36
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant.rb +0 -4
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant/abstract.rb +0 -137
- data/vendor/rufus-tokyo/lib/rufus/edo/ntyrant/table.rb +0 -141
- data/vendor/rufus-tokyo/lib/rufus/edo/tabcore.rb +0 -567
- data/vendor/rufus-tokyo/lib/rufus/tokyo.rb +0 -58
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/abstract.rb +0 -568
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/lib.rb +0 -230
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/table.rb +0 -753
- data/vendor/rufus-tokyo/lib/rufus/tokyo/cabinet/util.rb +0 -425
- data/vendor/rufus-tokyo/lib/rufus/tokyo/config.rb +0 -161
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia.rb +0 -43
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia/lib.rb +0 -65
- data/vendor/rufus-tokyo/lib/rufus/tokyo/dystopia/words.rb +0 -71
- data/vendor/rufus-tokyo/lib/rufus/tokyo/hmethods.rb +0 -111
- data/vendor/rufus-tokyo/lib/rufus/tokyo/query.rb +0 -102
- data/vendor/rufus-tokyo/lib/rufus/tokyo/transactions.rb +0 -74
- data/vendor/rufus-tokyo/lib/rufus/tokyo/ttcommons.rb +0 -59
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant.rb +0 -35
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/abstract.rb +0 -146
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/lib.rb +0 -153
- data/vendor/rufus-tokyo/lib/rufus/tokyo/tyrant/table.rb +0 -162
- data/vendor/rufus-tokyo/rufus-tokyo.gemspec +0 -25
- data/vendor/rufus-tokyo/spec/cabinet_spec.rb +0 -472
- data/vendor/rufus-tokyo/spec/cabinetconfig_spec.rb +0 -82
- data/vendor/rufus-tokyo/spec/edo_cabinet_spec.rb +0 -447
- data/vendor/rufus-tokyo/spec/edo_ntyrant_spec.rb +0 -299
- data/vendor/rufus-tokyo/spec/edo_ntyrant_table_spec.rb +0 -462
- data/vendor/rufus-tokyo/spec/edo_table_spec.rb +0 -560
- data/vendor/rufus-tokyo/spec/hmethods_spec.rb +0 -44
- data/vendor/rufus-tokyo/spec/incr.lua +0 -20
- data/vendor/rufus-tokyo/spec/spec.rb +0 -9
- data/vendor/rufus-tokyo/spec/spec_base.rb +0 -23
- data/vendor/rufus-tokyo/spec/start_tyrants.sh +0 -26
- data/vendor/rufus-tokyo/spec/stop_tyrants.sh +0 -9
- data/vendor/rufus-tokyo/spec/table_spec.rb +0 -567
- data/vendor/rufus-tokyo/spec/tyrant_spec.rb +0 -309
- data/vendor/rufus-tokyo/spec/tyrant_table_spec.rb +0 -479
- data/vendor/rufus-tokyo/spec/util_list_spec.rb +0 -200
- data/vendor/rufus-tokyo/spec/util_map_spec.rb +0 -132
- data/vendor/rufus-tokyo/tasks/dev.rb +0 -70
- data/vendor/rufus-tokyo/test/bm0.rb +0 -353
- data/vendor/rufus-tokyo/test/bm1_compression.rb +0 -54
- data/vendor/rufus-tokyo/test/con0.rb +0 -30
- data/vendor/rufus-tokyo/test/mem.rb +0 -49
- data/vendor/rufus-tokyo/test/mem1.rb +0 -44
- data/vendor/rufus-tokyo/test/readme0.rb +0 -17
- data/vendor/rufus-tokyo/test/readme1.rb +0 -21
- data/vendor/rufus-tokyo/test/readme2.rb +0 -15
- data/vendor/rufus-tokyo/test/readme3.rb +0 -24
- data/vendor/rufus-tokyo/test/readmes_test.sh +0 -17
data/lib/metry/memory.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Metry
|
2
|
-
class Memory
|
3
|
-
def initialize
|
4
|
-
clear
|
5
|
-
end
|
6
|
-
|
7
|
-
def <<(event)
|
8
|
-
@hash[:events][(@hash[:event] += 1).to_s] = event
|
9
|
-
end
|
10
|
-
|
11
|
-
def size
|
12
|
-
@hash[:events].size
|
13
|
-
end
|
14
|
-
|
15
|
-
def [](id)
|
16
|
-
@hash[:events][id]
|
17
|
-
end
|
18
|
-
|
19
|
-
def next_visitor
|
20
|
-
@hash[:visitor] += 1
|
21
|
-
end
|
22
|
-
|
23
|
-
def clear
|
24
|
-
@hash = {:events => {}, :visitor => 0, :event => 0}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/metry/tokyo.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rufus/tokyo'
|
3
|
-
require 'rufus/edo'
|
4
|
-
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
module Metry
|
8
|
-
class Tokyo
|
9
|
-
EVENT_PREFIX = "event_"
|
10
|
-
VISITOR_PREFIX = "visitor_"
|
11
|
-
META_PREFIX = "meta_"
|
12
|
-
|
13
|
-
def initialize(file, interface="Edo")
|
14
|
-
FileUtils.mkdir_p(::File.dirname(file))
|
15
|
-
@file = "#{file}.tdb"
|
16
|
-
@store = Rufus.const_get(interface)::Table
|
17
|
-
end
|
18
|
-
|
19
|
-
def next_visitor
|
20
|
-
access do |storage|
|
21
|
-
storage.incr("#{META_PREFIX}visitor")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def visitor(id)
|
26
|
-
access do |storage|
|
27
|
-
(storage[visitor_id(id)] || {})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def visitor_count
|
32
|
-
access do |storage|
|
33
|
-
storage.query do |q|
|
34
|
-
q.add '', :starts_with, VISITOR_PREFIX
|
35
|
-
q.pk_only
|
36
|
-
end.size
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def visitors
|
41
|
-
access do |storage|
|
42
|
-
r = storage.query do |q|
|
43
|
-
q.add '', :starts_with, VISITOR_PREFIX
|
44
|
-
end.to_a
|
45
|
-
r.each{|e| e[:pk].sub!(/^#{VISITOR_PREFIX}/, '')}
|
46
|
-
r
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def save_visitor(id, hash={})
|
51
|
-
access do |storage|
|
52
|
-
storage[visitor_id(id)] = (visitor(id) || {}).merge(hash)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def <<(event)
|
57
|
-
access do |storage|
|
58
|
-
storage[next_event_id(storage)] = event.inject({}){|a,(k,v)| a[k] = v.to_s; a}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def [](id)
|
63
|
-
access do |storage|
|
64
|
-
storage[event_id(id)]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def event_count
|
69
|
-
access do |storage|
|
70
|
-
storage.keys(:prefix => EVENT_PREFIX).size
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def events_for(visitor)
|
75
|
-
access do |storage|
|
76
|
-
storage.query do |q|
|
77
|
-
q.add '', :starts_with, EVENT_PREFIX
|
78
|
-
q.add 'visitor', :eq, visitor
|
79
|
-
end.to_a
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def last_events(count=1)
|
84
|
-
access do |storage|
|
85
|
-
storage.query do |q|
|
86
|
-
q.add '', :starts_with, EVENT_PREFIX
|
87
|
-
q.order_by "time", :numdesc
|
88
|
-
q.limit count
|
89
|
-
end.to_a
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def all_events
|
94
|
-
access do |storage|
|
95
|
-
storage.query do |q|
|
96
|
-
q.add '', :starts_with, EVENT_PREFIX
|
97
|
-
end.to_a
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def clear
|
102
|
-
access do |storage|
|
103
|
-
storage.clear
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def next_event_id(storage)
|
110
|
-
event_id(storage.incr("#{META_PREFIX}event"))
|
111
|
-
end
|
112
|
-
|
113
|
-
def access
|
114
|
-
key = "metry_storage"
|
115
|
-
created_storage ||= false
|
116
|
-
unless storage = Thread.current[key]
|
117
|
-
created_storage = true
|
118
|
-
Thread.current[key] = storage = @store.new(@file, :mode => "wc")
|
119
|
-
end
|
120
|
-
begin
|
121
|
-
result = yield(storage)
|
122
|
-
ensure
|
123
|
-
if created_storage
|
124
|
-
storage.close
|
125
|
-
Thread.current[key] = nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
result
|
129
|
-
end
|
130
|
-
|
131
|
-
def visitor_id(id)
|
132
|
-
"#{VISITOR_PREFIX}#{id}"
|
133
|
-
end
|
134
|
-
|
135
|
-
def event_id(id)
|
136
|
-
"#{EVENT_PREFIX}#{id}"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
module Rufus::Tokyo
|
142
|
-
class Table
|
143
|
-
# Increments the value stored under the given key with the given increment
|
144
|
-
# (defaults to 1 (integer)).
|
145
|
-
#
|
146
|
-
# Accepts an integer or a double value.
|
147
|
-
#
|
148
|
-
def incr (key, inc=1)
|
149
|
-
|
150
|
-
v = inc.is_a?(Fixnum) ?
|
151
|
-
lib.addint(@db, key, Rufus::Tokyo.blen(key), inc) :
|
152
|
-
lib.adddouble(@db, key, Rufus::Tokyo.blen(key), inc)
|
153
|
-
|
154
|
-
raise(TokyoError.new(
|
155
|
-
"incr failed, there is probably already a string value set " +
|
156
|
-
"for the key '#{key}'"
|
157
|
-
)) if v == Rufus::Tokyo::INT_MIN || (v.respond_to?(:nan?) && v.nan?)
|
158
|
-
|
159
|
-
v
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
module Rufus::Edo
|
165
|
-
class Table
|
166
|
-
# Increments the value stored under the given key with the given increment
|
167
|
-
# (defaults to 1 (integer)).
|
168
|
-
#
|
169
|
-
def incr (key, val=1)
|
170
|
-
|
171
|
-
v = val.is_a?(Fixnum) ? @db.addint(key, val) : @db.adddouble(key, val)
|
172
|
-
|
173
|
-
raise(EdoError.new(
|
174
|
-
"incr failed, there is probably already a string value set " +
|
175
|
-
"for the key '#{key}'"
|
176
|
-
)) unless v
|
177
|
-
|
178
|
-
v
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
|
2
|
-
= rufus-tokyo CHANGELOG.txt
|
3
|
-
|
4
|
-
|
5
|
-
== rufus-tokyo - 0.1.14 not yet released
|
6
|
-
|
7
|
-
- issue #2 : query#add with no_index=false by default
|
8
|
-
- issue #1 : added query#delete and table#query_delete
|
9
|
-
|
10
|
-
|
11
|
-
== rufus-tokyo - 0.1.13 released 2009/06/02
|
12
|
-
|
13
|
-
- todo : putkeep implementation (by Kamal)
|
14
|
-
- todo : support for binary data (map, list, cabinet, table, tokyo/edo)
|
15
|
-
- todo : added #defrag to Rufus::Tokyo::Cabinet
|
16
|
-
- todo : added :dfunit to databases that support it
|
17
|
-
- todo : added #addint and #adddouble (#incr)
|
18
|
-
|
19
|
-
|
20
|
-
== rufus-tokyo - 0.1.12 released 2009/04/07
|
21
|
-
|
22
|
-
- todo : added ext method for calling embedded Lua function (Tyrant)
|
23
|
-
- todo : added transaction support for Rufus::Tokyo::Cabinet
|
24
|
-
- todo : mimicking query.count in rufus/edo
|
25
|
-
- todo : implemented query.count (TC 1.4.12 and TT 1.1.20 only) rufus/tokyo
|
26
|
-
|
27
|
-
|
28
|
-
== rufus-tokyo - 0.1.11 released 2009/03/25
|
29
|
-
|
30
|
-
- todo : autodetecting /usr/lib/libtokyocabinet.so and
|
31
|
-
/usr/lib/libtokyotyrant.so (thanks mebaran)
|
32
|
-
|
33
|
-
|
34
|
-
== rufus-tokyo - 0.1.10 released 2009/03/19
|
35
|
-
|
36
|
-
- bug : had to adapt to TC 1.4.10 and TT 1.1.17 new "setlimit"
|
37
|
-
|
38
|
-
|
39
|
-
== rufus-tokyo - 0.1.9 released 2009/02/27
|
40
|
-
|
41
|
-
- bug : sudo gem install rufus-tokyo was failing because of
|
42
|
-
lib/tokyotyrant.rb. Fixed.
|
43
|
-
|
44
|
-
|
45
|
-
== rufus-tokyo - 0.1.8 released 2009/02/27
|
46
|
-
|
47
|
-
- added : support for Hirabayashi-san 'native' Ruby classes via Rufus::Edo
|
48
|
-
- todo : implemented #delete_keys_with_prefix (naive impl for tables)
|
49
|
-
- added : lget/ldelete and merge! to Rufus::Tokyo::Cabinet and ::Tyrant
|
50
|
-
|
51
|
-
|
52
|
-
== rufus-tokyo - 0.1.7 released 2009/02/19
|
53
|
-
|
54
|
-
- todo : Rufus::Tokyo::Cabinet.new('filename', :type => :hash) now OK (Zev)
|
55
|
-
- todo : more documentation for Rufus::Tokyo::Cabinet#new
|
56
|
-
- added : Rufus::Tokyo::Cabinet has a open method that takes a block like
|
57
|
-
File.open (Zev)
|
58
|
-
- todo : aligned Rufus::Tokyo::Table#new on ::Cabinet#new
|
59
|
-
- todo : added opts (:prefix, :limit, :native) to Rufus::Tokyo::Cabinet#keys,
|
60
|
-
Rufus::Tokyo::Table#keys and the corresponding Tyrant classes
|
61
|
-
|
62
|
-
|
63
|
-
== rufus-tokyo - 0.1.6 released 2009/02/16
|
64
|
-
|
65
|
-
- todo : Tyrant and TyrantTable now complain when used in lieu of each other
|
66
|
-
- todo : implemented Tyrant and TyrantTable #stat
|
67
|
-
- todo : made tran begin/abort/commit directly available (framework builders)
|
68
|
-
- todo : implemented Rufus::Tokyo::Table#transaction
|
69
|
-
- bug : JRuby support back in
|
70
|
-
- todo : implemented Rufus::Tokyo::Map#[] (class method)
|
71
|
-
- todo : simplified Table and TyrantTable #[]=
|
72
|
-
- bug : preventing table#[]= from segfaulting on bad input (Justin)
|
73
|
-
|
74
|
-
|
75
|
-
== rufus-tokyo - 0.1.5 released 2009/02/13
|
76
|
-
|
77
|
-
- todo : implemented set_index (cabinet / tyrant tables)
|
78
|
-
- todo : namespace simplification (Justin)
|
79
|
-
- todo : implemented Rufus::Tokyo::TyrantTable
|
80
|
-
- todo : implemented Rufus::Tokyo::Tyrant
|
81
|
-
- todo : moved tests to bacon (spec/)
|
82
|
-
|
83
|
-
|
84
|
-
== rufus-tokyo - 0.1.4 released 2009/02/02
|
85
|
-
|
86
|
-
- todo #23780 : hmethods for Rufus::Tokyo::Table
|
87
|
-
|
88
|
-
|
89
|
-
== rufus-tokyo - 0.1.3 released 2009/01/29
|
90
|
-
|
91
|
-
- todo : implemented Rufus::Tokyo::Table (and query)
|
92
|
-
- todo : implemented Rufus::Tokyo::List
|
93
|
-
- todo : implemented Rufus::Tokyo::Map
|
94
|
-
- todo : implemented Cabinet#compact_copy
|
95
|
-
- todo : implemented Cabinet#copy
|
96
|
-
|
97
|
-
|
98
|
-
== rufus-tokyo - 0.1.2 released 2009/01/23
|
99
|
-
|
100
|
-
- todo : implemented Cabinet#keys and #values
|
101
|
-
|
102
|
-
|
103
|
-
== rufus-tokyo - 0.1.1 released 2009/01/23
|
104
|
-
|
105
|
-
- bug : fixed dependency, it's ffi not ruby-ffi
|
106
|
-
- todo : implemented Cabinet#clear
|
107
|
-
|
108
|
-
|
109
|
-
== rufus-tokyo - 0.1.0 released 2009/01/23
|
110
|
-
|
111
|
-
- initial release
|
112
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
= CREDITS.txt rufus-tokyo gem
|
3
|
-
|
4
|
-
|
5
|
-
== authors
|
6
|
-
|
7
|
-
John Mettraux http://jmettraux.wordpress.com
|
8
|
-
Zev Blut http://www.iknow.co.jp/users/zev
|
9
|
-
|
10
|
-
|
11
|
-
== contributors
|
12
|
-
|
13
|
-
Matthew King http://github.com/automatthew
|
14
|
-
Kamal Fariz Mahyuddin http://github.com/kamal
|
15
|
-
Justin Reagor http://blog.kineticweb.com/
|
16
|
-
Benjami Yu http://github.com/byu
|
17
|
-
Mark 'mebaran' http://github.com/mebaran
|
18
|
-
|
19
|
-
|
20
|
-
== finally
|
21
|
-
|
22
|
-
many thanks to the author of Tokyo Cabinet (Mikio Hirabayashi) and
|
23
|
-
the authors of ruby-ffi
|
24
|
-
|
25
|
-
http://tokyocabinet.sourceforge.net
|
26
|
-
http://kenai.com/projects/ruby-ffi
|
27
|
-
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
|
3
|
-
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
of this software and associated documentation files (the "Software"), to deal
|
6
|
-
in the Software without restriction, including without limitation the rights
|
7
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
copies of the Software, and to permit persons to whom the Software is
|
9
|
-
furnished to do so, subject to the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be included in
|
12
|
-
all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
THE SOFTWARE.
|
21
|
-
|
@@ -1,310 +0,0 @@
|
|
1
|
-
|
2
|
-
= rufus-tokyo
|
3
|
-
|
4
|
-
ruby-ffi based interface to Tokyo Cabinet and Tokyo Tyrant.
|
5
|
-
|
6
|
-
The 'abstract' and the 'table' API are covered for now.
|
7
|
-
|
8
|
-
|
9
|
-
== installation
|
10
|
-
|
11
|
-
sudo gem install rufus-tokyo
|
12
|
-
|
13
|
-
(see after 'usage' for how to install Tokyo Cabinet (and Tyrant) if required)
|
14
|
-
|
15
|
-
|
16
|
-
== Rufus::Edo
|
17
|
-
|
18
|
-
Note : Rufus::Tokyo focuses on leveraging Hirabayashi-san's C libraries via ruby-ffi, but the gem rufus-tokyo also contains Rufus::Edo which wraps the Tokyo Cabinet/Tyrant author's [native] C bindings :
|
19
|
-
|
20
|
-
http://github.com/jmettraux/rufus-tokyo/tree/master/lib/rufus/edo
|
21
|
-
|
22
|
-
|
23
|
-
== usage
|
24
|
-
|
25
|
-
hereafter TC references Tokyo Cabinet, while TT references Tokyo Tyrant.
|
26
|
-
|
27
|
-
the rdoc is at http://rufus.rubyforge.org/rufus-tokyo/
|
28
|
-
|
29
|
-
|
30
|
-
== version [mis]match
|
31
|
-
|
32
|
-
this version of rufus-tokyo works with
|
33
|
-
|
34
|
-
ffi 0.3.1, 0.3.5
|
35
|
-
|
36
|
-
ruby 1.8.6
|
37
|
-
ruby 1.9.1p0
|
38
|
-
jruby 1.1.6
|
39
|
-
jruby 1.2.0
|
40
|
-
|
41
|
-
TC 1.4.9 and TT 1.1.16
|
42
|
-
TC 1.4.10 and TT 1.1.17 (adds the offset arg to query.limit)
|
43
|
-
TC 1.4.11 and TT 1.1.18
|
44
|
-
TC 1.4.13 and TT 1.1.22 (added query.count)
|
45
|
-
TC 1.4.21 and TT 1.1.27
|
46
|
-
|
47
|
-
tc-ruby 1.20 and tt-ruby 1.3 (Rufus::Edo)
|
48
|
-
tc-ruby 1.21 and tt-ruby 1.5 (Rufus::Edo)
|
49
|
-
tc-ruby 1.21 and tt-ruby 1.7 (Rufus::Edo)
|
50
|
-
|
51
|
-
|
52
|
-
=== TC Abstract API
|
53
|
-
|
54
|
-
http://tokyocabinet.sourceforge.net/spex-en.html#tcadbapi
|
55
|
-
|
56
|
-
to create a hash (file named 'data.tch')
|
57
|
-
|
58
|
-
require 'rubygems'
|
59
|
-
require 'rufus/tokyo'
|
60
|
-
|
61
|
-
db = Rufus::Tokyo::Cabinet.new('data.tch')
|
62
|
-
|
63
|
-
db['nada'] = 'surf'
|
64
|
-
|
65
|
-
p db['nada'] # => 'surf'
|
66
|
-
p db['lost'] # => nil
|
67
|
-
|
68
|
-
5000.times { |i| db[i.to_s] = "x" }
|
69
|
-
|
70
|
-
p db.inject { |r, (k, v)| k } # => 4999
|
71
|
-
|
72
|
-
db.close
|
73
|
-
|
74
|
-
|
75
|
-
=== TC Table API
|
76
|
-
|
77
|
-
http://tokyocabinet.sourceforge.net/spex-en.html#tctdbapi
|
78
|
-
|
79
|
-
require 'rubygems'
|
80
|
-
require 'rufus/tokyo'
|
81
|
-
|
82
|
-
t = Rufus::Tokyo::Table.new('table.tct')
|
83
|
-
|
84
|
-
t['pk0'] = { 'name' => 'alfred', 'age' => '22' }
|
85
|
-
t['pk1'] = { 'name' => 'bob', 'age' => '18' }
|
86
|
-
t['pk2'] = { 'name' => 'charly', 'age' => '45' }
|
87
|
-
t['pk3'] = { 'name' => 'doug', 'age' => '77' }
|
88
|
-
t['pk4'] = { 'name' => 'ephrem', 'age' => '32' }
|
89
|
-
|
90
|
-
p t.query { |q|
|
91
|
-
q.add_condition 'age', :numge, '32'
|
92
|
-
q.order_by 'age'
|
93
|
-
}
|
94
|
-
# => [ {"name"=>"ephrem", :pk=>"pk4", "age"=>"32"},
|
95
|
-
# {"name"=>"charly", :pk=>"pk2", "age"=>"45"} ]
|
96
|
-
|
97
|
-
t.close
|
98
|
-
|
99
|
-
Note that the Tokyo Cabinet Table API does support transactions :
|
100
|
-
|
101
|
-
p t.size
|
102
|
-
# => 0
|
103
|
-
|
104
|
-
t.transaction do
|
105
|
-
t['pk0'] = { 'name' => 'alfred', 'age' => '22' }
|
106
|
-
t['pk1'] = { 'name' => 'bob', 'age' => '18' }
|
107
|
-
t.abort
|
108
|
-
end
|
109
|
-
|
110
|
-
p t.size
|
111
|
-
# => 0
|
112
|
-
|
113
|
-
|
114
|
-
=== TT remote db
|
115
|
-
|
116
|
-
http://tokyocabinet.sourceforge.net/tyrantdoc/
|
117
|
-
|
118
|
-
to start a ttserver (backed by a hash), on the command line
|
119
|
-
|
120
|
-
ttserver -port 45001 data.tch
|
121
|
-
|
122
|
-
|
123
|
-
then, in Ruby :
|
124
|
-
|
125
|
-
require 'rubygems'
|
126
|
-
require 'rufus/tokyo/tyrant'
|
127
|
-
|
128
|
-
db = Rufus::Tokyo::Tyrant.new('localhost', 45001)
|
129
|
-
|
130
|
-
db['nada'] = 'surf'
|
131
|
-
|
132
|
-
p db['nada'] # => 'surf'
|
133
|
-
p db['lost'] # => nil
|
134
|
-
|
135
|
-
db.close
|
136
|
-
|
137
|
-
|
138
|
-
Rufus::Tokyo::Tyrant instances have a #stat method :
|
139
|
-
|
140
|
-
puts db.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
|
141
|
-
# =>
|
142
|
-
# pid => 7566
|
143
|
-
# loadavg => 0.398438
|
144
|
-
# size => 528736
|
145
|
-
# rnum => 0
|
146
|
-
# time => 1234764065.305923
|
147
|
-
# sid => 898521513
|
148
|
-
# type => hash
|
149
|
-
# bigend => 0
|
150
|
-
# ru_sys => 3.398698
|
151
|
-
# version => 1.1.15
|
152
|
-
# ru_user => 2.155215
|
153
|
-
# ru_real => 3218.451152
|
154
|
-
# fd => 7
|
155
|
-
|
156
|
-
|
157
|
-
Note that it's also OK to make a Tokyo Tyrant server listen on a unix socket :
|
158
|
-
|
159
|
-
ttserver -host /tmp/ttsocket -port 0 data.tch
|
160
|
-
|
161
|
-
and then :
|
162
|
-
|
163
|
-
require 'rubygems'
|
164
|
-
require 'rufus/tokyo/tyrant'
|
165
|
-
db = Rufus::Tokyo::Tyrant.new('/tmp/ttsocket')
|
166
|
-
db['a'] = 'alpha'
|
167
|
-
db.close
|
168
|
-
|
169
|
-
|
170
|
-
=== TT remote table
|
171
|
-
|
172
|
-
to start a ttserver (backed by a table), on the command line :
|
173
|
-
|
174
|
-
ttserver -port 45002 data.tct
|
175
|
-
|
176
|
-
|
177
|
-
then, in Ruby, much like a local table :
|
178
|
-
|
179
|
-
require 'rubygems'
|
180
|
-
require 'rufus/tokyo/tyrant'
|
181
|
-
|
182
|
-
t = Rufus::Tokyo::TyrantTable.new('localhost', 45002)
|
183
|
-
|
184
|
-
t['pk0'] = { 'name' => 'alfred', 'age' => '22' }
|
185
|
-
t['pk1'] = { 'name' => 'bob', 'age' => '18' }
|
186
|
-
t['pk2'] = { 'name' => 'charly', 'age' => '45' }
|
187
|
-
t['pk3'] = { 'name' => 'doug', 'age' => '77' }
|
188
|
-
t['pk4'] = { 'name' => 'ephrem', 'age' => '32' }
|
189
|
-
|
190
|
-
p t.query { |q|
|
191
|
-
q.add_condition 'age', :numge, '32'
|
192
|
-
q.order_by 'age'
|
193
|
-
}
|
194
|
-
# => [ {"name"=>"ephrem", :pk=>"pk4", "age"=>"32"},
|
195
|
-
# {"name"=>"charly", :pk=>"pk2", "age"=>"45"} ]
|
196
|
-
|
197
|
-
t.close
|
198
|
-
|
199
|
-
|
200
|
-
Rufus::Tokyo::TyrantTable instances have a #stat method :
|
201
|
-
|
202
|
-
puts t.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
|
203
|
-
# =>
|
204
|
-
# pid => 7569
|
205
|
-
# loadavg => 0.295410
|
206
|
-
# size => 935792
|
207
|
-
# rnum => 0
|
208
|
-
# time => 1234764228.942014
|
209
|
-
# sid => 1027604232
|
210
|
-
# type => table
|
211
|
-
# bigend => 0
|
212
|
-
# ru_sys => 5.966750
|
213
|
-
# version => 1.1.15
|
214
|
-
# ru_user => 2.601947
|
215
|
-
# ru_real => 3382.084479
|
216
|
-
# fd => 10
|
217
|
-
|
218
|
-
|
219
|
-
Note that it's also OK to make a Tokyo Tyrant server listen on a unix socket :
|
220
|
-
|
221
|
-
ttserver -host /tmp/tttsocket -port 0 data.tct
|
222
|
-
|
223
|
-
and then :
|
224
|
-
|
225
|
-
require 'rubygems'
|
226
|
-
require 'rufus/tokyo/tyrant'
|
227
|
-
t = Rufus::Tokyo::TyrantTable.new('/tmp/tttsocket')
|
228
|
-
t['customer0'] = { 'name' => 'Heike no Kyomori', 'age' => '75' }
|
229
|
-
t.close
|
230
|
-
|
231
|
-
|
232
|
-
== rdoc
|
233
|
-
|
234
|
-
more in the rdoc
|
235
|
-
|
236
|
-
http://rufus.rubyforge.org/rufus-tokyo/
|
237
|
-
http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Cabinet.html
|
238
|
-
http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Table.html
|
239
|
-
http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Tyrant.html
|
240
|
-
http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/TyrantTable.html
|
241
|
-
|
242
|
-
don't hesitate to "man ttserver" on the command line.
|
243
|
-
|
244
|
-
or directly in the source
|
245
|
-
|
246
|
-
http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/abstract.rb
|
247
|
-
http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/table.rb
|
248
|
-
http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/abstract.rb
|
249
|
-
http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/table.rb
|
250
|
-
|
251
|
-
|
252
|
-
== Tokyo Cabinet / Tyrant install
|
253
|
-
|
254
|
-
a compilation of notes is available at :
|
255
|
-
|
256
|
-
http://openwferu.rubyforge.org/tokyo.html
|
257
|
-
|
258
|
-
|
259
|
-
== dependencies
|
260
|
-
|
261
|
-
the ruby gem 'ffi'
|
262
|
-
|
263
|
-
|
264
|
-
== mailing list
|
265
|
-
|
266
|
-
On the rufus-ruby list :
|
267
|
-
|
268
|
-
http://groups.google.com/group/rufus-ruby
|
269
|
-
|
270
|
-
|
271
|
-
== issue tracker
|
272
|
-
|
273
|
-
http://github.com/jmettraux/rufus-tokyo/issues/
|
274
|
-
|
275
|
-
|
276
|
-
== irc
|
277
|
-
|
278
|
-
irc.freenode.net #ruote
|
279
|
-
|
280
|
-
|
281
|
-
== source
|
282
|
-
|
283
|
-
http://github.com/jmettraux/rufus-tokyo
|
284
|
-
|
285
|
-
git clone git://github.com/jmettraux/rufus-tokyo.git
|
286
|
-
|
287
|
-
|
288
|
-
== credits
|
289
|
-
|
290
|
-
many thanks to the author of Tokyo Cabinet, Mikio Hirabayashi, and to the authors of ruby-ffi
|
291
|
-
|
292
|
-
http://tokyocabinet.sourceforge.net
|
293
|
-
http://kenai.com/projects/ruby-ffi
|
294
|
-
|
295
|
-
|
296
|
-
== authors
|
297
|
-
|
298
|
-
John Mettraux, jmettraux@gmail.com, http://jmettraux.wordpress.com
|
299
|
-
Zev Blut, http://www.iknow.co.jp/users/zev
|
300
|
-
|
301
|
-
|
302
|
-
== the rest of Rufus
|
303
|
-
|
304
|
-
http://rufus.rubyforge.org
|
305
|
-
|
306
|
-
|
307
|
-
== license
|
308
|
-
|
309
|
-
MIT
|
310
|
-
|