about processes and engines

rufus-tokyo 0.1.5, hail to the Tyrant

golfIf you go to the the Tokyo Cabinet page, you’ll sometimes be welcome with a banner saying “Nagoya Cabinet” or “Shinjuku Cupboard”, no worries, you’re at the right place.

The two main projects of Mikio Hirabayashi are Tokyo Cabinet (local hash / table) and Tokyo Tyrant (remote Tokyo Cabinet).

After supporting Tokyo Cabinet in rufus-tokyo 0.1.4, Justin and I included support for Tokyo Tyrant in rufus-tokyo 0.1.5.

Getting Tokyo Cabinet and Tyrant is relatively easy, it boils down to getting the source from and then unpacking them and running “./configure && make && sudo make” for both of them (a more detailed description of the compile/install steps).

# start a tyrant server from the command line :
#   ttserver -port 45000 data.tch

require 'rubygems'
require 'rufus/tokyo' # sudo gem install 'rufus-tokyo'

t ='localhost', 45000)

t['shinjuku'] = 'twin towers'
t['ikebukuro'] = 'pond bag'

p t['ikebukuro'] # => 'pond bag'


Looks great, but since Tokyo Tyrant speaks kling… memcached, one is probably better served (in terms of performance) by a classic ruby memcached client library.

Still there is one area where rufus-tokyo + Tokyo Tyrant could make sense :

# on the command line, launch a tyrant server with a stable structure :
#   ttserver -port 45001 data.tct
# (note the .tct suffix, it indicates to the Tyrant it has to create
# a table structure)

require 'rubygems'
require 'rufus/tokyo/tyrant' # sudo gem install 'rufus-tokyo'

t ='localhost', 45001)

t['pk0'] = { 'name' => 'jim', 'age' => '25', 'lang' => 'ja,en' }
t['pk1'] = { 'name' => 'jeff', 'age' => '32', 'lang' => 'en,es' }
t['pk2'] = { 'name' => 'jack', 'age' => '44', 'lang' => 'en' }
t['pk3'] = { 'name' => 'jake', 'age' => '45', 'lang' => 'en,li' }

# ...

p t.keys
  # => [ 'pk0', 'pk1', 'pk2', 'pk3' ]

p t.query { |q|
  q.add 'lang', :includes, 'en'
  q.limit 2
  # =>
  # [{"name"=>"jim", :pk=>"pk0", "lang"=>"ja,en", "age"=>"25"},
  #  {"name"=>"jeff", :pk=>"pk1", "lang"=>"en,es", "age"=>"32"}]

# ...


There is one potential and interesting development for rufus-tokyo : Yehuda Katz integrated it into Moneta, his “unified interface to key/value stores”. Looking forward to see how it develops.

Many thanks to Justin, Yehuda and Zev for their work/support/help.

Tested with Ruby 1.8.6 and Ruby 1.9.1p0 (There is a small issue with JRuby 1.1.6, I hope to solve it very soon and release a 0.1.6 for it).

Written by John Mettraux

February 13, 2009 at 3:08 am

7 Responses

Subscribe to comments with RSS.

  1. Oh joy! I’ve been wanting something like this for a while now. Just add validations and I’m set. dm-adapter for yet?


    February 16, 2009 at 3:15 am

  2. Thanks will probably work on cheapRoc/dm-tyrant-adapter if possible.


    February 16, 2009 at 4:00 am

  3. […] Rufus 0.1.5 Release Notes – […]

  4. line 11 should now read:

    require ‘rufus/tokyo/tyrant’


    June 24, 2009 at 6:47 pm

  5. […] of the project, is actively maintaining the Tokyo Cabinet (rdoc) and Tokyo Tyrant (rdoc) libraries. John Mettraux is working on a FFI-backed, and arguably much more Ruby friendly version: rufus-tokyo, and Makoto Inoue has a prototype […]

Comments are closed.

%d bloggers like this: