Find file
Fetching contributors…
Cannot retrieve contributors at this time
75 lines (48 sloc) 1.95 KB


Just a place for me to keep experiments with Tokyo Cabinet which is a persistent hash which is extremely efficient.

If you have any fun examples of usage, feel free to fork and add them in!

These examples were originally pulled from the tokyo documentation and blog posts and adapted by Nathan Esquenazi.



This is a simple guide to installing Tokyo Cabinet and using the system with Ruby.

First install Tokyo Cabinet:

git clone git://
cd tokyo-cabinet/
sudo make install

Then install the ruby bindings:

sudo gem install ffi
sudo gem install rufus-tokyo


Tokyo Cabinet with Basic Store:

require 'rubygems'
require 'rufus/tokyo'

db ='data.tch')

db['nada'] = 'surf'

p db['nada'] # => 'surf'
p db['lost'] # => nil


and with Table Store:

require "rubygems"
require "rufus/tokyo/cabinet/table"

t ='table.tdb', :create, :write)

t['pk0'] = { 'name' => 'alfred', 'age' => '22', 'sex' => 'male' }
t['pk1'] = { 'name' => 'bob', 'age' => '18' }
t['pk2'] = { 'name' => 'charly', 'age' => '45', 'nickname' => 'charlie' }
t['pk3'] = { 'name' => 'doug', 'age' => '77' }
t['pk4'] = { 'name' => 'ephrem', 'age' => '32' }

p t.query { |q|
  q.add_condition 'age', :numge, '32'
  q.order_by 'age'


Check the examples folder for additional usage samples! Or feel free to fork and add your own.